Mercurial > hg > Members > shoshi > jungle > jungle-core
view src/test/java/DefaultJungleTreeTest.java @ 175:e26462a38ce0
add push pop
author | tatsuki |
---|---|
date | Fri, 06 Mar 2015 10:44:50 +0900 |
parents | 6615db346bf5 |
children | e5275a599048 |
line wrap: on
line source
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.store.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import junit.framework.Assert; import junit.framework.TestCase; public class DefaultJungleTreeTest extends TestCase { public Jungle instance() { Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor(new DefaultTraverser())); 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"); Assert.assertEquals(0, tree.revision()); 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 ; TreeNode node = tree.getRootNode(); ByteBuffer v = node.getAttributes().get(key); Assert.assertEquals(0, v.compareTo(value)); Assert.assertEquals(1, tree.revision()); // 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(r.isA()); } public void testIsolation() { } }