Skip to main content
summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorBrian Vosburgh2016-02-09 20:17:36 +0000
committerBrian Vosburgh2017-05-18 22:36:40 +0000
commit58f8009dfc8da1db4636b6f0894b8fbb77a57525 (patch)
treeb12eb542e42d7a3bcbec784ae896d26cb223692f /common
parent739c12ddf5271314bc15e7b52d7ffffeaff6eb3d (diff)
downloadwebtools.dali-58f8009dfc8da1db4636b6f0894b8fbb77a57525.tar.gz
webtools.dali-58f8009dfc8da1db4636b6f0894b8fbb77a57525.tar.xz
webtools.dali-58f8009dfc8da1db4636b6f0894b8fbb77a57525.zip
clean up Stack tests
Diffstat (limited to 'common')
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/CachingConcurrentStack.java2
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ConcurrentStack.java2
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/CachingConcurrentStackTests.java157
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ConcurrentStackTests.java157
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackTests.java171
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackToolsTests.java82
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/SynchronizedStackTests.java5
7 files changed, 265 insertions, 311 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/CachingConcurrentStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/CachingConcurrentStack.java
index 6bcd3588da..fdea14d1b3 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/CachingConcurrentStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/CachingConcurrentStack.java
@@ -17,7 +17,7 @@ import org.eclipse.jpt.common.utility.stack.Stack;
/**
* Linked LIFO implementation of the {@link Stack} interface
- * that provides non-blocking, lock-free concurrent access.
+ * that provides lock-free concurrent access.
* The stack's internal nodes are cached and re-used.
* <p>
* Unlike most of the other stack implementations, this stack
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ConcurrentStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ConcurrentStack.java
index d45d2de52e..5b21ee69a3 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ConcurrentStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ConcurrentStack.java
@@ -16,7 +16,7 @@ import org.eclipse.jpt.common.utility.stack.Stack;
/**
* Linked LIFO implementation of the {@link Stack} interface
- * that provides non-blocking, lock-free concurrent access.
+ * that provides lock-free concurrent access.
* <p>
* Unlike most of the other stack implementations, this stack
* does not accept <code>null</code> elements and returns <code>null</code>
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/CachingConcurrentStackTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/CachingConcurrentStackTests.java
index 3e68f24b94..64672fbf82 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/CachingConcurrentStackTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/CachingConcurrentStackTests.java
@@ -9,13 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.stack;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Vector;
-import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.internal.reference.SynchronizedBoolean;
-import org.eclipse.jpt.common.utility.internal.stack.CachingConcurrentStack;
import org.eclipse.jpt.common.utility.internal.stack.StackTools;
import org.eclipse.jpt.common.utility.stack.Stack;
@@ -32,154 +26,9 @@ public class CachingConcurrentStackTests
return StackTools.cachingConcurrentStack();
}
- public void testConcurrentAccess() throws InterruptedException {
- CachingConcurrentStack<Integer> stack = StackTools.cachingConcurrentStack();
-
- int threadCount = 10;
- int elementsPerThread = 100000;
- SynchronizedBoolean startFlag = new SynchronizedBoolean(false);
-
- PushRunnable[] pushRunnables = new PushRunnable[threadCount];
- Thread[] pushThreads = new Thread[threadCount];
- for (int i = 0; i < threadCount; i++) {
- PushRunnable pushRunnable = new PushRunnable(stack, (i * elementsPerThread), elementsPerThread, startFlag);
- pushRunnables[i] = pushRunnable;
- Thread pushThread = new Thread(pushRunnable);
- pushThreads[i] = pushThread;
- pushThread.start();
- }
-
- PopRunnable[] popRunnables = new PopRunnable[threadCount];
- Thread[] popThreads = new Thread[threadCount];
- for (int i = 0; i < threadCount; i++) {
- PopRunnable popRunnable = new PopRunnable(stack, elementsPerThread, startFlag);
- popRunnables[i] = popRunnable;
- Thread popThread = new Thread(popRunnable);
- popThreads[i] = popThread;
- popThread.start();
- }
-
- startFlag.setTrue();
- for (int i = 0; i < threadCount; i++) {
- pushThreads[i].join();
- assertTrue(pushRunnables[i].exceptions.isEmpty());
- }
- for (int i = 0; i < threadCount; i++) {
- popThreads[i].join();
- assertTrue(popRunnables[i].exceptions.isEmpty());
- }
-
- // if we get here, we have, at the least, popd as many elements as we pushd...
- // ...now verify that all the popd elements are unique
- // (i.e. none were lost or duplicated)
- int totalCount = threadCount * elementsPerThread;
- int uberMax = totalCount + 1;
- int uberMaxThreadIndex = threadCount + 1;
- int[] indexes = ArrayTools.fill(new int[threadCount], 0);
- for (int i = 0; i < totalCount; i++) {
- int min = uberMax;
- int minThreadIndex = uberMaxThreadIndex;
- for (int j = 0; j < threadCount; j++) {
- int currentIndex = indexes[j];
- if (currentIndex < elementsPerThread) {
- int current = popRunnables[j].elements[currentIndex].intValue();
- if (current < min) {
- min = current;
- minThreadIndex = j;
- }
- }
- }
- assertEquals(i, min);
- indexes[minThreadIndex]++;
- }
- }
-
- public static class PushRunnable
- implements Runnable
- {
- private final Stack<Integer> stack;
- private final int start;
- private final int stop;
- private final SynchronizedBoolean startFlag;
- final List<InterruptedException> exceptions = new Vector<>();
-
- public PushRunnable(Stack<Integer> stack, int start, int count, SynchronizedBoolean startFlag) {
- super();
- this.stack = stack;
- this.start = start;
- this.stop = start + count;
- this.startFlag = startFlag;
- }
-
- public void run() {
- try {
- this.run_();
- } catch (InterruptedException ex) {
- this.exceptions.add(ex);
- }
- }
-
- private void run_() throws InterruptedException {
- this.startFlag.waitUntilTrue();
- for (int i = this.start; i < this.stop; i++) {
- this.stack.push(Integer.valueOf(i));
- if ((i % 20) == 0) {
- Thread.sleep(0);
- }
- }
- }
- }
-
- public static class PopRunnable
- implements Runnable
- {
- private final Stack<Integer> stack;
- private final int count;
- final Integer[] elements;
- private int elementsCount;
- private final SynchronizedBoolean startFlag;
- final List<InterruptedException> exceptions = new Vector<>();
-
- public PopRunnable(Stack<Integer> stack, int count, SynchronizedBoolean startFlag) {
- super();
- this.stack = stack;
- this.count = count;
- this.elements = new Integer[count];
- this.elementsCount = 0;
- this.startFlag = startFlag;
- }
-
- public void run() {
- try {
- this.run_();
- } catch (InterruptedException ex) {
- this.exceptions.add(ex);
- }
- }
-
- private void run_() throws InterruptedException {
- this.startFlag.waitUntilTrue();
- int i = 0;
- while (true) {
- Integer element = this.stack.peek(); // fiddle with peek also
- element = this.stack.pop();
- if (element != null) {
- this.elements[this.elementsCount++] = element;
- if (this.elementsCount == this.count) {
- break;
- }
- }
- if ((i % 20) == 0) {
- Thread.sleep(0);
- }
- if (i == Integer.MAX_VALUE) {
- i = 0;
- } else {
- i++;
- }
- }
- Arrays.sort(this.elements);
- }
+ @Override
+ Stack<Integer> buildConcurrentStack() {
+ return StackTools.cachingConcurrentStack();
}
public void testCache() {
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ConcurrentStackTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ConcurrentStackTests.java
index 613517b73c..c218b33c11 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ConcurrentStackTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ConcurrentStackTests.java
@@ -9,13 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.stack;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Vector;
-import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.internal.reference.SynchronizedBoolean;
-import org.eclipse.jpt.common.utility.internal.stack.ConcurrentStack;
import org.eclipse.jpt.common.utility.internal.stack.StackTools;
import org.eclipse.jpt.common.utility.stack.Stack;
@@ -32,154 +26,9 @@ public class ConcurrentStackTests
return StackTools.concurrentStack();
}
- public void testConcurrentAccess() throws InterruptedException {
- ConcurrentStack<Integer> stack = StackTools.concurrentStack();
-
- int threadCount = 10;
- int elementsPerThread = 100000;
- SynchronizedBoolean startFlag = new SynchronizedBoolean(false);
-
- PushRunnable[] pushRunnables = new PushRunnable[threadCount];
- Thread[] pushThreads = new Thread[threadCount];
- for (int i = 0; i < threadCount; i++) {
- PushRunnable pushRunnable = new PushRunnable(stack, (i * elementsPerThread), elementsPerThread, startFlag);
- pushRunnables[i] = pushRunnable;
- Thread pushThread = new Thread(pushRunnable);
- pushThreads[i] = pushThread;
- pushThread.start();
- }
-
- PopRunnable[] popRunnables = new PopRunnable[threadCount];
- Thread[] popThreads = new Thread[threadCount];
- for (int i = 0; i < threadCount; i++) {
- PopRunnable popRunnable = new PopRunnable(stack, elementsPerThread, startFlag);
- popRunnables[i] = popRunnable;
- Thread popThread = new Thread(popRunnable);
- popThreads[i] = popThread;
- popThread.start();
- }
-
- startFlag.setTrue();
- for (int i = 0; i < threadCount; i++) {
- pushThreads[i].join();
- assertTrue(pushRunnables[i].exceptions.isEmpty());
- }
- for (int i = 0; i < threadCount; i++) {
- popThreads[i].join();
- assertTrue(popRunnables[i].exceptions.isEmpty());
- }
-
- // if we get here, we have, at the least, popd as many elements as we pushd...
- // ...now verify that all the popd elements are unique
- // (i.e. none were lost or duplicated)
- int totalCount = threadCount * elementsPerThread;
- int uberMax = totalCount + 1;
- int uberMaxThreadIndex = threadCount + 1;
- int[] indexes = ArrayTools.fill(new int[threadCount], 0);
- for (int i = 0; i < totalCount; i++) {
- int min = uberMax;
- int minThreadIndex = uberMaxThreadIndex;
- for (int j = 0; j < threadCount; j++) {
- int currentIndex = indexes[j];
- if (currentIndex < elementsPerThread) {
- int current = popRunnables[j].elements[currentIndex].intValue();
- if (current < min) {
- min = current;
- minThreadIndex = j;
- }
- }
- }
- assertEquals(i, min);
- indexes[minThreadIndex]++;
- }
- }
-
- public static class PushRunnable
- implements Runnable
- {
- private final Stack<Integer> stack;
- private final int start;
- private final int stop;
- private final SynchronizedBoolean startFlag;
- final List<InterruptedException> exceptions = new Vector<>();
-
- public PushRunnable(Stack<Integer> stack, int start, int count, SynchronizedBoolean startFlag) {
- super();
- this.stack = stack;
- this.start = start;
- this.stop = start + count;
- this.startFlag = startFlag;
- }
-
- public void run() {
- try {
- this.run_();
- } catch (InterruptedException ex) {
- this.exceptions.add(ex);
- }
- }
-
- private void run_() throws InterruptedException {
- this.startFlag.waitUntilTrue();
- for (int i = this.start; i < this.stop; i++) {
- this.stack.push(Integer.valueOf(i));
- if ((i % 20) == 0) {
- Thread.sleep(0);
- }
- }
- }
- }
-
- public static class PopRunnable
- implements Runnable
- {
- private final Stack<Integer> stack;
- private final int count;
- final Integer[] elements;
- private int elementsCount;
- private final SynchronizedBoolean startFlag;
- final List<InterruptedException> exceptions = new Vector<>();
-
- public PopRunnable(Stack<Integer> stack, int count, SynchronizedBoolean startFlag) {
- super();
- this.stack = stack;
- this.count = count;
- this.elements = new Integer[count];
- this.elementsCount = 0;
- this.startFlag = startFlag;
- }
-
- public void run() {
- try {
- this.run_();
- } catch (InterruptedException ex) {
- this.exceptions.add(ex);
- }
- }
-
- private void run_() throws InterruptedException {
- this.startFlag.waitUntilTrue();
- int i = 0;
- while (true) {
- Integer element = this.stack.peek(); // fiddle with peek also
- element = this.stack.pop();
- if (element != null) {
- this.elements[this.elementsCount++] = element;
- if (this.elementsCount == this.count) {
- break;
- }
- }
- if ((i % 20) == 0) {
- Thread.sleep(0);
- }
- if (i == Integer.MAX_VALUE) {
- i = 0;
- } else {
- i++;
- }
- }
- Arrays.sort(this.elements);
- }
+ @Override
+ Stack<Integer> buildConcurrentStack() {
+ return StackTools.concurrentStack();
}
public void testNodeToString() {
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackTests.java
index 54fc775ef1..9c2aecf0f8 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,8 +9,13 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.stack;
+import java.util.Arrays;
import java.util.EmptyStackException;
+import java.util.List;
+import java.util.Vector;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.reference.SynchronizedBoolean;
import org.eclipse.jpt.common.utility.stack.Stack;
import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
@@ -166,4 +171,168 @@ public abstract class StackTests
assertEquals("[third, second, first]", stack.toString());
}
+
+ // ********** concurrency **********
+
+ Stack<Integer> buildConcurrentStack() {
+ return null;
+ }
+
+ public void testConcurrentAccess() throws InterruptedException {
+ Stack<Integer> stack = this.buildConcurrentStack();
+ if (stack == null) {
+ return;
+ }
+
+ int threadCount = 10;
+ int elementsPerThread = 100000;
+ SynchronizedBoolean startFlag = new SynchronizedBoolean(false);
+
+ PushRunnable[] pushRunnables = new PushRunnable[threadCount];
+ Thread[] pushThreads = new Thread[threadCount];
+ for (int i = 0; i < threadCount; i++) {
+ PushRunnable pushRunnable = new PushRunnable(stack, (i * elementsPerThread), elementsPerThread, startFlag);
+ pushRunnables[i] = pushRunnable;
+ Thread pushThread = new Thread(pushRunnable, "Push-" + i);
+ pushThreads[i] = pushThread;
+ pushThread.start();
+ }
+
+ PopRunnable[] popRunnables = new PopRunnable[threadCount];
+ Thread[] popThreads = new Thread[threadCount];
+ for (int i = 0; i < threadCount; i++) {
+ PopRunnable popRunnable = new PopRunnable(stack, elementsPerThread, startFlag);
+ popRunnables[i] = popRunnable;
+ Thread popThread = new Thread(popRunnable, "Pop-" + i);
+ popThreads[i] = popThread;
+ popThread.start();
+ }
+
+ startFlag.setTrue();
+ for (int i = 0; i < threadCount; i++) {
+ pushThreads[i].join();
+ assertTrue(pushRunnables[i].exceptions.isEmpty());
+ }
+ for (int i = 0; i < threadCount; i++) {
+ popThreads[i].join();
+ assertTrue(popRunnables[i].exceptions.isEmpty());
+ }
+
+ // if we get here, we have, at the least, popped as many elements as we pushed...
+ // ...now verify that all the popped elements are unique
+ // (i.e. none were lost or duplicated)
+ int totalCount = threadCount * elementsPerThread;
+ int uberMax = totalCount + 1;
+ int uberMaxThreadIndex = threadCount + 1;
+ int[] indexes = ArrayTools.fill(new int[threadCount], 0);
+ for (int i = 0; i < totalCount; i++) {
+ int min = uberMax;
+ int minThreadIndex = uberMaxThreadIndex;
+ for (int j = 0; j < threadCount; j++) {
+ int currentIndex = indexes[j];
+ if (currentIndex < elementsPerThread) {
+ int current = popRunnables[j].elements[currentIndex].intValue();
+ if (current < min) {
+ min = current;
+ minThreadIndex = j;
+ }
+ }
+ }
+ assertEquals(i, min);
+ indexes[minThreadIndex]++;
+ }
+ }
+
+ public static class PushRunnable
+ implements Runnable
+ {
+ private final Stack<Integer> stack;
+ private final int start;
+ private final int stop;
+ private final SynchronizedBoolean startFlag;
+ final List<InterruptedException> exceptions = new Vector<>();
+
+ public PushRunnable(Stack<Integer> stack, int start, int count, SynchronizedBoolean startFlag) {
+ super();
+ this.stack = stack;
+ this.start = start;
+ this.stop = start + count;
+ this.startFlag = startFlag;
+ }
+
+ public void run() {
+ try {
+ this.run_();
+ } catch (InterruptedException ex) {
+ this.exceptions.add(ex);
+ }
+ }
+
+ private void run_() throws InterruptedException {
+ this.startFlag.waitUntilTrue();
+ for (int i = this.start; i < this.stop; i++) {
+ this.stack.push(Integer.valueOf(i));
+ if ((i % 20) == 0) {
+ Thread.sleep(0);
+ }
+ }
+ }
+ }
+
+ public static class PopRunnable
+ implements Runnable
+ {
+ private final Stack<Integer> stack;
+ private final int count;
+ final Integer[] elements;
+ private int elementsCount;
+ private final SynchronizedBoolean startFlag;
+ final List<InterruptedException> exceptions = new Vector<>();
+
+ public PopRunnable(Stack<Integer> stack, int count, SynchronizedBoolean startFlag) {
+ super();
+ this.stack = stack;
+ this.count = count;
+ this.elements = new Integer[count];
+ this.elementsCount = 0;
+ this.startFlag = startFlag;
+ }
+
+ public void run() {
+ try {
+ this.run_();
+ } catch (InterruptedException ex) {
+ this.exceptions.add(ex);
+ }
+ }
+
+ private void run_() throws InterruptedException {
+ this.startFlag.waitUntilTrue();
+ int i = 0;
+ while (true) {
+ Integer element = null;
+ try {
+ element = this.stack.peek(); // fiddle with peek also
+ element = this.stack.pop();
+ } catch (EmptyStackException ex) {
+ element = null;
+ }
+ if (element != null) {
+ this.elements[this.elementsCount++] = element;
+ if (this.elementsCount == this.count) {
+ break;
+ }
+ }
+ if ((i % 20) == 0) {
+ Thread.sleep(0);
+ }
+ if (i == Integer.MAX_VALUE) {
+ i = 0;
+ } else {
+ i++;
+ }
+ }
+ Arrays.sort(this.elements);
+ }
+ }
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackToolsTests.java
index e9167bf12c..e1e8e592b1 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackToolsTests.java
@@ -19,6 +19,8 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.queue.ArrayQueue;
import org.eclipse.jpt.common.utility.internal.queue.QueueTools;
import org.eclipse.jpt.common.utility.internal.stack.ArrayStack;
+import org.eclipse.jpt.common.utility.internal.stack.CachingConcurrentStack;
+import org.eclipse.jpt.common.utility.internal.stack.ConcurrentStack;
import org.eclipse.jpt.common.utility.internal.stack.LinkedStack;
import org.eclipse.jpt.common.utility.internal.stack.StackTools;
import org.eclipse.jpt.common.utility.internal.stack.SynchronizedStack;
@@ -406,6 +408,86 @@ public class StackToolsTests
assertEquals("one", stack.pop());
}
+ // ********** concurrent stack **********
+
+ public void testConcurrentStack() {
+ ConcurrentStack<String> d = StackTools.concurrentStack();
+ assertTrue(d.isEmpty());
+ }
+
+ public void testConcurrentStackIterable() {
+ ArrayList<String> iterable = new ArrayList<>();
+ iterable.add("one");
+ iterable.add("two");
+ iterable.add("three");
+ Stack<String> stack = StackTools.concurrentStack(iterable);
+ assertEquals("three", stack.pop());
+ assertEquals("two", stack.pop());
+ assertEquals("one", stack.pop());
+ }
+
+ public void testConcurrentStackIterator() {
+ ArrayList<String> iterable = new ArrayList<>();
+ iterable.add("one");
+ iterable.add("two");
+ iterable.add("three");
+ Stack<String> stack = StackTools.concurrentStack(iterable.iterator());
+ assertEquals("three", stack.pop());
+ assertEquals("two", stack.pop());
+ assertEquals("one", stack.pop());
+ }
+
+ public void testConcurrentStackArray() {
+ ArrayList<String> iterable = new ArrayList<>();
+ iterable.add("one");
+ iterable.add("two");
+ iterable.add("three");
+ Stack<String> stack = StackTools.concurrentStack(iterable.toArray(StringTools.EMPTY_STRING_ARRAY));
+ assertEquals("three", stack.pop());
+ assertEquals("two", stack.pop());
+ assertEquals("one", stack.pop());
+ }
+
+ // ********** caching concurrent stack **********
+
+ public void testCachingConcurrentStack() {
+ CachingConcurrentStack<String> d = StackTools.cachingConcurrentStack();
+ assertTrue(d.isEmpty());
+ }
+
+ public void testCachingConcurrentStackIterable() {
+ ArrayList<String> iterable = new ArrayList<>();
+ iterable.add("one");
+ iterable.add("two");
+ iterable.add("three");
+ Stack<String> stack = StackTools.cachingConcurrentStack(iterable);
+ assertEquals("three", stack.pop());
+ assertEquals("two", stack.pop());
+ assertEquals("one", stack.pop());
+ }
+
+ public void testCachingConcurrentStackIterator() {
+ ArrayList<String> iterable = new ArrayList<>();
+ iterable.add("one");
+ iterable.add("two");
+ iterable.add("three");
+ Stack<String> stack = StackTools.cachingConcurrentStack(iterable.iterator());
+ assertEquals("three", stack.pop());
+ assertEquals("two", stack.pop());
+ assertEquals("one", stack.pop());
+ }
+
+ public void testCachingConcurrentStackArray() {
+ ArrayList<String> iterable = new ArrayList<>();
+ iterable.add("one");
+ iterable.add("two");
+ iterable.add("three");
+ Stack<String> stack = StackTools.cachingConcurrentStack(iterable.toArray(StringTools.EMPTY_STRING_ARRAY));
+ assertEquals("three", stack.pop());
+ assertEquals("two", stack.pop());
+ assertEquals("one", stack.pop());
+ }
+
// ********** fixed-capacity array stack **********
public void testFixedCapacityArrayStackCollection() {
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/SynchronizedStackTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/SynchronizedStackTests.java
index 2c51d3f4bc..deabb00f16 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/SynchronizedStackTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/SynchronizedStackTests.java
@@ -46,6 +46,11 @@ public class SynchronizedStackTests
}
@Override
+ Stack<Integer> buildConcurrentStack() {
+ return StackTools.synchronizedStack();
+ }
+
+ @Override
public void testClone() {
// synchronized stack is not cloneable
}

Back to the top