Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 47:22d8966ab672
added test
author | Shoshi TAMAKI |
---|---|
date | Tue, 05 Feb 2013 19:16:45 +0900 |
parents | e7d94437ca2f |
children | 962cf4e208a1 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java src/test/java/DefaultJungleTreeTest.java |
diffstat | 2 files changed, 65 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java Tue Feb 05 18:19:11 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java Tue Feb 05 19:16:45 2013 +0900 @@ -20,6 +20,7 @@ jungle.createNewTree("hoge"); JungleTree tree = jungle.getTreeByName("hoge"); JungleTreeEditor editor = tree.getTreeEditor(); + JungleTreeEditor editor2 = tree.getTreeEditor(); DefaultNodePath path = new DefaultNodePath(); String key = "key"; @@ -29,6 +30,7 @@ JungleTreeEditor e = either.b(); e.success(); + Node root = tree.getRootNode(); ByteBuffer v = root.getAttributes().get(key); String str = new String(v.array());
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/DefaultJungleTreeTest.java Tue Feb 05 19:16:45 2013 +0900 @@ -0,0 +1,63 @@ +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Result; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import junit.framework.Assert; +import junit.framework.TestCase; + + +public class DefaultJungleTreeTest extends TestCase +{ + public Jungle instance() + { + Jungle j = new DefaultJungle("hogehoge"); + return j; + } + + public static final String key = "KEY"; + public static final ByteBuffer value = ByteBuffer.wrap(key.getBytes()); + + public void testSampleTest() + { + Jungle j = instance(); + j.createNewTree("tree"); + JungleTree tree = j.getTreeByName("tree"); + + JungleTreeEditor editor1 = tree.getTreeEditor(); + JungleTreeEditor editor2 = tree.getTreeEditor(); + + DefaultNodePath root = new DefaultNodePath(); + + Either<Error,JungleTreeEditor> either = editor1.putAttribute(root,key,value); + if(either.isA()){ + Assert.fail(); + } + editor1 = either.b(); + editor1.success(); + + // check the value ; + Node node = tree.getRootNode(); + ByteBuffer v = node.getAttributes().get(key); + Assert.assertEquals(0,v.compareTo(value)); + + // editor2 must fail transction + either = editor2.putAttribute(root,key,value); + if(either.isA()){ + Assert.fail(); + } + editor2 = either.b(); + Either<Error,JungleTreeEditor> r = editor2.success(); + Assert.assertTrue(either.isA()); + } + + public void testIsolation() + { + + } +}