annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
1 import java.nio.ByteBuffer;
75
26dfa90016d1 error delete but 2 test program commentout and not action BulletinBoard
one
parents: 54
diff changeset
2
47
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
3 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle;
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
4 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
54
650fe2a0dccc modified tests
Shoshi TAMAKI
parents: 47
diff changeset
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
75
26dfa90016d1 error delete but 2 test program commentout and not action BulletinBoard
one
parents: 54
diff changeset
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
54
650fe2a0dccc modified tests
Shoshi TAMAKI
parents: 47
diff changeset
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
47
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
54
650fe2a0dccc modified tests
Shoshi TAMAKI
parents: 47
diff changeset
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
47
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
13 import junit.framework.Assert;
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
14 import junit.framework.TestCase;
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
15
166
6615db346bf5 miner change
one
parents: 152
diff changeset
16 public class DefaultJungleTreeTest extends TestCase {
6615db346bf5 miner change
one
parents: 152
diff changeset
17 public Jungle instance() {
6615db346bf5 miner change
one
parents: 152
diff changeset
18 Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor(new DefaultTraverser()));
6615db346bf5 miner change
one
parents: 152
diff changeset
19 return j;
6615db346bf5 miner change
one
parents: 152
diff changeset
20 }
47
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
21
166
6615db346bf5 miner change
one
parents: 152
diff changeset
22 public static final String key = "KEY";
6615db346bf5 miner change
one
parents: 152
diff changeset
23 public static final ByteBuffer value = ByteBuffer.wrap(key.getBytes());
6615db346bf5 miner change
one
parents: 152
diff changeset
24
6615db346bf5 miner change
one
parents: 152
diff changeset
25 public void testSampleTest() {
6615db346bf5 miner change
one
parents: 152
diff changeset
26 Jungle j = instance();
6615db346bf5 miner change
one
parents: 152
diff changeset
27 j.createNewTree("tree");
6615db346bf5 miner change
one
parents: 152
diff changeset
28 JungleTree tree = j.getTreeByName("tree");
6615db346bf5 miner change
one
parents: 152
diff changeset
29 Assert.assertEquals(0, tree.revision());
6615db346bf5 miner change
one
parents: 152
diff changeset
30 JungleTreeEditor editor1 = tree.getTreeEditor();
6615db346bf5 miner change
one
parents: 152
diff changeset
31 JungleTreeEditor editor2 = tree.getTreeEditor();
6615db346bf5 miner change
one
parents: 152
diff changeset
32
6615db346bf5 miner change
one
parents: 152
diff changeset
33 DefaultNodePath root = new DefaultNodePath();
6615db346bf5 miner change
one
parents: 152
diff changeset
34
6615db346bf5 miner change
one
parents: 152
diff changeset
35 Either<Error, JungleTreeEditor> either = editor1.putAttribute(root, key, value);
6615db346bf5 miner change
one
parents: 152
diff changeset
36 if (either.isA()) {
6615db346bf5 miner change
one
parents: 152
diff changeset
37 Assert.fail();
6615db346bf5 miner change
one
parents: 152
diff changeset
38 }
6615db346bf5 miner change
one
parents: 152
diff changeset
39 editor1 = either.b();
6615db346bf5 miner change
one
parents: 152
diff changeset
40 editor1.success();
6615db346bf5 miner change
one
parents: 152
diff changeset
41
6615db346bf5 miner change
one
parents: 152
diff changeset
42 // check the value ;
6615db346bf5 miner change
one
parents: 152
diff changeset
43 TreeNode node = tree.getRootNode();
6615db346bf5 miner change
one
parents: 152
diff changeset
44 ByteBuffer v = node.getAttributes().get(key);
6615db346bf5 miner change
one
parents: 152
diff changeset
45 Assert.assertEquals(0, v.compareTo(value));
6615db346bf5 miner change
one
parents: 152
diff changeset
46 Assert.assertEquals(1, tree.revision());
6615db346bf5 miner change
one
parents: 152
diff changeset
47 // editor2 must fail transction
6615db346bf5 miner change
one
parents: 152
diff changeset
48 either = editor2.putAttribute(root, key, value);
6615db346bf5 miner change
one
parents: 152
diff changeset
49 if (either.isA()) {
6615db346bf5 miner change
one
parents: 152
diff changeset
50 Assert.fail();
6615db346bf5 miner change
one
parents: 152
diff changeset
51 }
6615db346bf5 miner change
one
parents: 152
diff changeset
52 editor2 = either.b();
6615db346bf5 miner change
one
parents: 152
diff changeset
53 Either<Error, JungleTreeEditor> r = editor2.success();
6615db346bf5 miner change
one
parents: 152
diff changeset
54 Assert.assertTrue(r.isA());
6615db346bf5 miner change
one
parents: 152
diff changeset
55 }
6615db346bf5 miner change
one
parents: 152
diff changeset
56
6615db346bf5 miner change
one
parents: 152
diff changeset
57 public void testIsolation() {
6615db346bf5 miner change
one
parents: 152
diff changeset
58
6615db346bf5 miner change
one
parents: 152
diff changeset
59 }
47
22d8966ab672 added test
Shoshi TAMAKI
parents:
diff changeset
60 }