You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2015/11/02 18:14:58 UTC
[04/24] tomee git commit: OPENEJB-2119 test for OPENEJB-2119
OPENEJB-2119 test for OPENEJB-2119
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/c38e30dc
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/c38e30dc
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/c38e30dc
Branch: refs/heads/tomee-7.0.0-M1
Commit: c38e30dc9ef2bed4360249de7bde89f36638e992
Parents: d617e8b
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Sun Oct 18 19:11:25 2015 +0200
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Sun Oct 18 19:11:25 2015 +0200
----------------------------------------------------------------------
.../openejb/core/ivm/naming/NameNode.java | 6 ++
.../openejb/ivm/naming/IvmContextTest.java | 71 ++++++++++++++++++++
2 files changed, 77 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/c38e30dc/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/NameNode.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/NameNode.java b/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/NameNode.java
index 9c175e7..73f1326 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/NameNode.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/NameNode.java
@@ -82,6 +82,12 @@ public class NameNode implements Serializable {
} catch (final NameNotFoundException e) {
n = e;
}
+ } else if (!unbound) {
+ try {
+ return IvmContext.class.cast(getBinding()).mynode.resolve(name);
+ } catch (final NameNotFoundException e) {
+ n = e;
+ }
}
} else if (!unbound) {
return getBinding();
http://git-wip-us.apache.org/repos/asf/tomee/blob/c38e30dc/container/openejb-core/src/test/java/org/apache/openejb/ivm/naming/IvmContextTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/ivm/naming/IvmContextTest.java b/container/openejb-core/src/test/java/org/apache/openejb/ivm/naming/IvmContextTest.java
index 9322a95..398dc27 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/ivm/naming/IvmContextTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/ivm/naming/IvmContextTest.java
@@ -17,17 +17,38 @@
package org.apache.openejb.ivm.naming;
import org.apache.openejb.core.ivm.naming.IvmContext;
+import org.apache.openejb.core.ivm.naming.NameNode;
import org.apache.openejb.util.Contexts;
import org.junit.Test;
import javax.naming.Context;
import javax.naming.NamingException;
+import java.lang.reflect.Field;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class IvmContextTest {
@Test
+ public void rebind() throws NamingException {
+ final IvmContext root = IvmContext.createRootContext();
+ root.rebind("global/App.EAR/foo", "test");
+ final Context last = Contexts.createSubcontexts(root, "global/App.EAR/foo");
+ last.bind("foo", "test");
+
+ // first ensure all is bound correctly
+ assertEquals("test", root.lookup("global/App.EAR/foo"));
+ assertEquals("test", last.lookup("foo"));
+
+ // now rebound, shouldnt throw any exception
+ final Context lastContext = Contexts.createSubcontexts(root, "global/App.EAR/foo");
+ lastContext.rebind("foo", "test2");
+ root.rebind("global/App.EAR/foo", "test2");
+ assertEquals("test2", root.lookup("global/App.EAR/foo"));
+ assertEquals("test2", last.lookup("foo"));
+ }
+
+ @Test
public void unbind() throws NamingException {
final IvmContext context = new IvmContext();
context.bind("global/foo/Bar", "Bar");
@@ -78,4 +99,54 @@ public class IvmContextTest {
// ok
}
}
+
+ private void check(final NameNode node) {
+ if (node == null) {
+ return;
+ }
+
+ final int atomicHash = getAtomicHash(node);
+
+ checkLess(node, node.getLessTree(), atomicHash);
+ checkGrtr(node.getGrtrTree(), atomicHash);
+
+ check(node.getLessTree());
+ check(node.getGrtrTree());
+ }
+
+ private void checkLess(final NameNode reference, final NameNode node, final int hash) {
+ if (node == null) {
+ return;
+ }
+
+ if (getAtomicHash(node) >= hash) {
+ throw new IllegalStateException(node + " >= " + reference);
+ }
+
+ checkLess(node, node.getLessTree(), hash);
+ checkLess(node, node.getGrtrTree(), hash);
+ }
+
+ private void checkGrtr(final NameNode node, final int hash) {
+ if (node == null) {
+ return;
+ }
+
+ if (getAtomicHash(node) <= hash) {
+ throw new IllegalStateException();
+ }
+
+ checkGrtr(node.getLessTree(), hash);
+ checkGrtr(node.getGrtrTree(), hash);
+ }
+
+ private int getAtomicHash(final NameNode node) {
+ try {
+ final Field field = NameNode.class.getDeclaredField("atomicHash");
+ field.setAccessible(true);
+ return Integer.class.cast(field.get(node));
+ } catch (Exception e) {
+ throw new AssertionError();
+ }
+ }
}