Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 166:6615db346bf5
miner change
line wrap: on
line diff
--- a/build.gradle Mon Dec 08 10:49:53 2014 +0900 +++ b/build.gradle Wed Dec 24 14:33:17 2014 +0900 @@ -14,7 +14,7 @@ compile "commons-collections:commons-collections:3.2.1" compile "org.apache.maven.surefire:surefire-junit4:2.13" compile "com.google.guava:guava:12.0" - compile "org.functionaljava:functionaljava:3.1" + compile "org.functionaljava:functionaljava:4.2-beta-1" testCompile "junit:junit:4.7" }
--- a/pom.xml Mon Dec 08 10:49:53 2014 +0900 +++ b/pom.xml Wed Dec 24 14:33:17 2014 +0900 @@ -1,57 +1,58 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> - <groupId>jungle</groupId> - <artifactId>jungle-core</artifactId> - <version>0.0.3-SNAPSHOT</version> - <packaging>jar</packaging> + <groupId>jungle</groupId> + <artifactId>jungle-core</artifactId> + <version>0.0.3-SNAPSHOT</version> + <packaging>jar</packaging> - <name>jungle-core</name> - <url>http://maven.apache.org</url> + <name>jungle-core</name> + <url>http://maven.apache.org</url> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.7</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>12.0</version> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.2.1</version> - </dependency> - <dependency> - <groupId>org.functionaljava</groupId> - <artifactId>functionaljava</artifactId> - <version>4.1</version> - </dependency> - <dependency> - <groupId>org.apache.maven.surefire</groupId> - <artifactId>surefire-junit4</artifactId> - <version>2.13</version> -</dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - </plugins> - </build> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>12.0</version> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.2.1</version> + </dependency> + <dependency> + <groupId>org.functionaljava</groupId> + <artifactId>functionaljava</artifactId> + <version>4.2-beta-1</version> + </dependency> + + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-junit4</artifactId> + <version>2.13</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + </plugins> + </build> </project>
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Mon Dec 08 10:49:53 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Wed Dec 24 14:33:17 2014 +0900 @@ -64,21 +64,8 @@ }; IndexManager indexManager = new IndexManager(repository.getReservation()); - InterfaceTraverser traverser = new InterfaceTraverser(_newRoot, indexManager, true); - long t1 = System.currentTimeMillis(); + InterfaceTraverser traverser = new InterfaceTraverser(_newRoot, indexManager, false); traverser.createIndex(); - long t2 = System.currentTimeMillis(); - System.out.println("createIndexTime = " + (t2 - t1)); - File file = new File("./time/createParentIndexFunctionalJava"); - try { - PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file,true))); - pw.println(t2 - t1); - pw.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Index index = traverser.getIndex(); ParentIndex parentIndex = traverser.getParentIndex(); DefaultChangeSet newCs = new DefaultChangeSet(_newRoot, cs, list, uuid, _treeName, nextRevision, index.getIndex(),
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Mon Dec 08 10:49:53 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Wed Dec 24 14:33:17 2014 +0900 @@ -61,12 +61,12 @@ TreeNode targetNode = itNode.next(); if (parentUpdateFlag) parentIndex = parentIndex.set(targetNode); -// List<String> keys = targetNode.getAttributes().getKeys(); -// for (String key : keys) { -// String value = targetNode.getAttributes().getString(key); -// if (value != null) -// index = index.set(key, value, targetNode); -// } + List<String> keys = targetNode.getAttributes().getKeys(); + for (String key : keys) { + String value = targetNode.getAttributes().getString(key); + if (value != null) + index = index.set(key, value, targetNode); + } } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexManager.java Mon Dec 08 10:49:53 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexManager.java Wed Dec 24 14:33:17 2014 +0900 @@ -28,7 +28,7 @@ String treeName = cs.getTreeName(); long revision = cs.revision(); index.get("KER", "value"); - DefaultChangeSet newCs = new DefaultChangeSet(root, prev, cl, uuid, treeName, revision, index, parentIndex); + DefaultChangeSet newCs = new DefaultChangeSet(root, prev, cl, uuid, treeName, revision, index.getIndex(), parentIndex.getParentIndex()); DefaultTreeContext newTs = new DefaultTreeContext(root, newCs); reservation.set(newTs); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Mon Dec 08 10:49:53 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Wed Dec 24 14:33:17 2014 +0900 @@ -2,10 +2,10 @@ import java.util.Iterator; - import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.TreeMapOrd; +import fj.Ord; import fj.data.Option; import fj.data.TreeMap; @@ -14,7 +14,8 @@ private TreeMap<TreeNode, TreeNode> parentIndex; public ParentIndex() { - parentIndex = TreeMap.empty(TreeMapOrd.treeNodeOrd); + Ord<TreeNode> aaa = TreeMapOrd.treeNodeOrd; + parentIndex = TreeMap.empty(aaa); } public ParentIndex(TreeMap<TreeNode, TreeNode> parentIndex) {
--- a/src/test/java/DefaultJungleTreeTest.java Mon Dec 08 10:49:53 2014 +0900 +++ b/src/test/java/DefaultJungleTreeTest.java Wed Dec 24 14:33:17 2014 +0900 @@ -14,53 +14,48 @@ 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 class DefaultJungleTreeTest extends TestCase -{ - public Jungle instance() - { - Jungle j = new DefaultJungle(null,"hogehoge",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() - { - - } + 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() { + + } }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/GetOldTreeTest.java Mon Dec 08 10:49:53 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/GetOldTreeTest.java Wed Dec 24 14:33:17 2014 +0900 @@ -22,7 +22,7 @@ @Test public void getOldTreeTest() { - Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); + Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor(new DefaultTraverser())); jungle.createNewTree("tree"); JungleTree tree = jungle.getTreeByName("tree"); JungleTreeEditor editor = tree.getTreeEditor();
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/AddChildrenIndexTest.java Mon Dec 08 10:49:53 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/AddChildrenIndexTest.java Wed Dec 24 14:33:17 2014 +0900 @@ -1,7 +1,5 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.index; - - import java.nio.ByteBuffer; import java.util.Iterator; @@ -21,87 +19,87 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import junit.framework.Assert; public class AddChildrenIndexTest { - @Test - public void DeleteChildrenTest(){ - Jungle jungle = new DefaultJungle(null, "hogehoge",new DefaultTraverser()); - jungle.createNewTree("tree"); - JungleTree tree = jungle.getTreeByName("tree"); - createTree(tree); - tree.getRootNode(); - InterfaceTraverser ifTraverser = tree.getTraverser(); + @Test + public void DeleteChildrenTest() { + Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor(new DefaultTraverser())); + jungle.createNewTree("tree"); + JungleTree tree = jungle.getTreeByName("tree"); + createTree(tree); + tree.getRootNode(); + InterfaceTraverser ifTraverser = tree.getTraverser(true); - Iterator<Pair<TreeNode, NodePath>> pairIterator = ifTraverser.find((TreeNode node) -> { - ByteBuffer attribute = node.getAttributes().get(key); - if (attribute != null) { - byte[] byteAttribute = attribute.array(); - String str = new String(byteAttribute); - System.out.println("attribute = " + str); - return str.equals("<-1,0,1>"); - } - return false; - }, key, "<-1,0,1>"); + Iterator<TreeNode> pairIterator = ifTraverser.find((TreeNode node) -> { + ByteBuffer attribute = node.getAttributes().get(key); + if (attribute != null) { + byte[] byteAttribute = attribute.array(); + String str = new String(byteAttribute); + System.out.println("attribute = " + str); + return str.equals("<-1,0,1>"); + } + return false; + }, key, "<-1,0,1>"); + + for (; pairIterator.hasNext(); pairIterator.next()) { - for (;pairIterator.hasNext();pairIterator.next()) { - - } - ifTraverser.commitIndex(); - - IndexJungleTreeEditor editor = tree.getIndexTreeEditor(); - Either<Error, JungleTreeEditor> either = editor.addNewChildAt(new DefaultNodePath().add(0), 0); - either.b().success(); - - InterfaceTraverser newIfTraverser = tree.getTraverser(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = newIfTraverser.getIndex(); - Assert.assertEquals(newIndex.get(key).some().get("<-1,0,1>").some().head().right().toString(),"<-1,0,2>"); - - } - public static String key = "KEY"; - public static DefaultTreeNode factory = new DefaultTreeNode(); + } + ifTraverser.commit(); + + JungleTreeEditor editor = tree.getTreeEditor(); + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(new DefaultNodePath().add(0), 0); + either.b().success(); + + InterfaceTraverser newIfTraverser = tree.getTraverser(true); + Index newIndex = newIfTraverser.getIndex(); + Assert.assertEquals(newIndex.get(key,"<-1,0,1>").head().toString(), "<-1,0,2>"); + + } - public void createTree(JungleTree tree) { - NodePath root = new DefaultNodePath(); - createChildren(tree, root, 0); + public static String key = "KEY"; + public static DefaultTreeNode factory = new DefaultTreeNode(); + + public void createTree(JungleTree tree) { + NodePath root = new DefaultNodePath(); + createChildren(tree, root, 0); - for (int x = 0; x < 3; x++) { - createChildren(tree, root.add(0), x); - for (int y = 0; y < 3; y++) { - createChildren(tree, root.add(0).add(x), y); - } - } + for (int x = 0; x < 3; x++) { + createChildren(tree, root.add(0), x); + for (int y = 0; y < 3; y++) { + createChildren(tree, root.add(0).add(x), y); + } + } - } + } - public void createChildren(JungleTree tree, NodePath root, int num) { - JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 - Either<Error, JungleTreeEditor> either = editor - .addNewChildAt(root, num); // 新しく入れるところへのパス - if (either.isA()) { - Assert.fail(); - } - editor = either.b(); - either = editor.success(); - if (either.isA()) { - Assert.fail(); - } - NodePath childPath = root.add(num); - editor = tree.getTreeEditor(); - NodePath attribute = root.add(num); - System.out.println(attribute.toString()); - either = editor.putAttribute(childPath, key,ByteBuffer.wrap(attribute.toString().getBytes())); - if (either.isA()) { - Assert.fail(); - } - editor = either.b(); - either = editor.success(); - } + public void createChildren(JungleTree tree, NodePath root, int num) { + JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, num); // 新しく入れるところへのパス + if (either.isA()) { + Assert.fail(); + } + editor = either.b(); + either = editor.success(); + if (either.isA()) { + Assert.fail(); + } + NodePath childPath = root.add(num); + editor = tree.getTreeEditor(); + NodePath attribute = root.add(num); + System.out.println(attribute.toString()); + either = editor.putAttribute(childPath, key, ByteBuffer.wrap(attribute.toString().getBytes())); + if (either.isA()) { + Assert.fail(); + } + editor = either.b(); + either = editor.success(); + } }