Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2016-01-22 23:41:54 +0000
committerBrian Vosburgh2017-05-18 22:35:48 +0000
commit36fdfe422cfb0f5471286a42e3bfcf9382156868 (patch)
treed1d1eb7cd62b5732c049aefe2e3ff67b0e1caedb /common/tests
parent9ff05b4598018e5943fb8b8e0034a3566c11d408 (diff)
downloadwebtools.dali-36fdfe422cfb0f5471286a42e3bfcf9382156868.tar.gz
webtools.dali-36fdfe422cfb0f5471286a42e3bfcf9382156868.tar.xz
webtools.dali-36fdfe422cfb0f5471286a42e3bfcf9382156868.zip
add ConcurrentStack and CachingConcurrentStack
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/CachingConcurrentStackTests.java161
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ConcurrentStackTests.java110
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/JptCommonUtilityStackTests.java4
3 files changed, 274 insertions, 1 deletions
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
new file mode 100644
index 0000000000..eb05335c2c
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/CachingConcurrentStackTests.java
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.stack;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.stack.StackTools;
+import org.eclipse.jpt.common.utility.stack.Stack;
+
+@SuppressWarnings("nls")
+public class CachingConcurrentStackTests
+ extends StackTests
+{
+ public CachingConcurrentStackTests(String name) {
+ super(name);
+ }
+
+ @Override
+ Stack<String> buildStack() {
+ return StackTools.cachingConcurrentStack();
+ }
+
+ public void testCache() {
+ Stack<String> stack = this.buildStack();
+ String first = "first";
+ String second = "second";
+ String third = "third";
+ String fourth = "fourth";
+ String fifth = "fifth";
+
+ this.verifyNodeCache(0, stack);
+ stack.push(first);
+ this.verifyNodeCache(0, stack);
+ stack.push(second);
+ stack.push(third);
+ stack.push(fourth);
+ stack.push(fifth);
+ this.verifyNodeCache(0, stack);
+ Object headRef = ObjectTools.get(stack, "cacheHeadRef");
+ assertNull(ObjectTools.get(headRef, "value"));
+
+ stack.pop();
+ this.verifyNodeCache(1, stack);
+ stack.pop();
+ this.verifyNodeCache(2, stack);
+ stack.pop();
+ this.verifyNodeCache(3, stack);
+ stack.pop();
+ this.verifyNodeCache(4, stack);
+ stack.pop();
+ this.verifyNodeCache(5, stack);
+ stack.push(first);
+ this.verifyNodeCache(4, stack);
+ stack.push(second);
+ this.verifyNodeCache(3, stack);
+ stack.push(third);
+ this.verifyNodeCache(2, stack);
+ stack.push(fourth);
+ this.verifyNodeCache(1, stack);
+ stack.push(fifth);
+ this.verifyNodeCache(0, stack);
+ }
+
+ public void verifyNodeCache(int size, Object stack) {
+ int nodeCount = 0;
+ Object headRef = ObjectTools.get(stack, "cacheHeadRef");
+ for (Object node = ObjectTools.get(headRef, "value"); node != null; node = ObjectTools.get(node, "next")) {
+ nodeCount++;
+ }
+ assertEquals(size, nodeCount);
+ }
+
+ public void testNodeToString() {
+ Stack<String> stack = this.buildStack();
+ String first = "first";
+ String second = "second";
+ String third = "third";
+ stack.push(first);
+ stack.push(second);
+ stack.push(third);
+
+ Object headRef = ObjectTools.get(stack, "headRef");
+ Object pair = ObjectTools.get(headRef, "pair");
+ Object head = ObjectTools.get(pair, "reference");
+ assertTrue(head.toString().startsWith("CachingConcurrentStack.Node"));
+ assertTrue(head.toString().endsWith("(third)"));
+ }
+
+ public void testPushNullException() {
+ Stack<String> stack = this.buildStack();
+ boolean exCaught = false;
+ try {
+ stack.push(null);
+ fail();
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ @Override
+ public void testEmptyStackExceptionPeek() {
+ // different behavior
+ }
+
+ public void testEmptyStackPeek() {
+ Stack<String> stack = this.buildStack();
+ String first = "first";
+ String second = "second";
+
+ stack.push(first);
+ stack.push(second);
+ assertEquals(second, stack.peek());
+ assertEquals(second, stack.pop());
+ assertEquals(first, stack.peek());
+ assertEquals(first, stack.pop());
+
+ assertNull(stack.peek());
+ }
+
+ @Override
+ public void testEmptyStackExceptionPop() {
+ // different behavior
+ }
+
+ public void testEmptyStackPop() {
+ Stack<String> stack = this.buildStack();
+ String first = "first";
+ String second = "second";
+
+ stack.push(first);
+ stack.push(second);
+ assertEquals(second, stack.peek());
+ assertEquals(second, stack.pop());
+ assertEquals(first, stack.peek());
+ assertEquals(first, stack.pop());
+
+ assertNull(stack.pop());
+ }
+
+ @Override
+ public void testSerialization() throws Exception {
+ // unsupported
+ }
+
+ @Override
+ public void testSerialization_empty() throws Exception {
+ // unsupported
+ }
+
+ @Override
+ public void testClone() {
+ // unsupported
+ }
+}
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
new file mode 100644
index 0000000000..0eaac8583b
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ConcurrentStackTests.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.stack;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.stack.StackTools;
+import org.eclipse.jpt.common.utility.stack.Stack;
+
+@SuppressWarnings("nls")
+public class ConcurrentStackTests
+ extends StackTests
+{
+ public ConcurrentStackTests(String name) {
+ super(name);
+ }
+
+ @Override
+ Stack<String> buildStack() {
+ return StackTools.concurrentStack();
+ }
+
+ public void testNodeToString() {
+ Stack<String> stack = this.buildStack();
+ String first = "first";
+ String second = "second";
+ String third = "third";
+ stack.push(first);
+ stack.push(second);
+ stack.push(third);
+
+ Object headRef = ObjectTools.get(stack, "headRef");
+ Object head = ObjectTools.get(headRef, "value");
+ assertTrue(head.toString().startsWith("ConcurrentStack.Node"));
+ assertTrue(head.toString().endsWith("(third)"));
+ }
+
+ public void testPushNullException() {
+ Stack<String> stack = this.buildStack();
+ boolean exCaught = false;
+ try {
+ stack.push(null);
+ fail();
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ @Override
+ public void testEmptyStackExceptionPeek() {
+ // different behavior
+ }
+
+ public void testEmptyStackPeek() {
+ Stack<String> stack = this.buildStack();
+ String first = "first";
+ String second = "second";
+
+ stack.push(first);
+ stack.push(second);
+ assertEquals(second, stack.peek());
+ assertEquals(second, stack.pop());
+ assertEquals(first, stack.peek());
+ assertEquals(first, stack.pop());
+
+ assertNull(stack.peek());
+ }
+
+ @Override
+ public void testEmptyStackExceptionPop() {
+ // different behavior
+ }
+
+ public void testEmptyStackPop() {
+ Stack<String> stack = this.buildStack();
+ String first = "first";
+ String second = "second";
+
+ stack.push(first);
+ stack.push(second);
+ assertEquals(second, stack.peek());
+ assertEquals(second, stack.pop());
+ assertEquals(first, stack.peek());
+ assertEquals(first, stack.pop());
+
+ assertNull(stack.pop());
+ }
+
+ @Override
+ public void testSerialization() throws Exception {
+ // unsupported
+ }
+
+ @Override
+ public void testSerialization_empty() throws Exception {
+ // unsupported
+ }
+
+ @Override
+ public void testClone() {
+ // unsupported
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/JptCommonUtilityStackTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/JptCommonUtilityStackTests.java
index f1ff723c3e..11115ffccb 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/JptCommonUtilityStackTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/JptCommonUtilityStackTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2005, 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.
@@ -21,6 +21,8 @@ public class JptCommonUtilityStackTests {
TestSuite suite = new TestSuite(JptCommonUtilityStackTests.class.getPackage().getName());
suite.addTestSuite(ArrayStackTests.class);
+ suite.addTestSuite(CachingConcurrentStackTests.class);
+ suite.addTestSuite(ConcurrentStackTests.class);
suite.addTestSuite(DequeStackTests.class);
suite.addTestSuite(EmptyStackTests.class);
suite.addTestSuite(FixedCapacityArrayStackTests.class);

Back to the top