Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 343:441c9edcb6b0
add BBSTest
author | nozomi |
---|---|
date | Wed, 13 Sep 2017 16:29:43 +0900 |
parents | 7d40ac7e693f |
children | 3fc39bff7a67 |
files | .idea/gradle.xml .idea/modules.xml .idea/vcs.xml jungle-core.iml src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/bbs/BBSTest.java |
diffstat | 5 files changed, 323 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/gradle.xml Wed Sep 13 16:29:43 2017 +0900 @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="GradleSettings"> + <option name="linkedExternalProjectsSettings"> + <GradleProjectSettings> + <option name="distributionType" value="DEFAULT_WRAPPED" /> + <option name="externalProjectPath" value="$PROJECT_DIR$" /> + <option name="gradleHome" value="/usr/local/share/gradle" /> + <option name="gradleJvm" value="1.8" /> + <option name="modules"> + <set> + <option value="$PROJECT_DIR$" /> + </set> + </option> + <option name="myModules"> + <set> + <option value="$PROJECT_DIR$" /> + </set> + </option> + </GradleProjectSettings> + </option> + </component> +</project> \ No newline at end of file
--- a/.idea/modules.xml Mon Aug 28 17:19:44 2017 +0900 +++ b/.idea/modules.xml Wed Sep 13 16:29:43 2017 +0900 @@ -2,12 +2,7 @@ <project version="4"> <component name="ProjectModuleManager"> <modules> - <module fileurl="file://$PROJECT_DIR$/.idea/modules/Alice.iml" filepath="$PROJECT_DIR$/.idea/modules/Alice.iml" /> - <module fileurl="file://$PROJECT_DIR$/.idea/modules/Alice_main.iml" filepath="$PROJECT_DIR$/.idea/modules/Alice_main.iml" group="Alice" /> - <module fileurl="file://$PROJECT_DIR$/.idea/modules/Alice_test.iml" filepath="$PROJECT_DIR$/.idea/modules/Alice_test.iml" group="Alice" /> <module fileurl="file://$PROJECT_DIR$/jungle-core.iml" filepath="$PROJECT_DIR$/jungle-core.iml" /> - <module fileurl="file://$PROJECT_DIR$/.idea/modules/jungle-core_main.iml" filepath="$PROJECT_DIR$/.idea/modules/jungle-core_main.iml" group="jungle-core" /> - <module fileurl="file://$PROJECT_DIR$/.idea/modules/jungle-core_test.iml" filepath="$PROJECT_DIR$/.idea/modules/jungle-core_test.iml" group="jungle-core" /> </modules> </component> </project> \ No newline at end of file
--- a/.idea/vcs.xml Mon Aug 28 17:19:44 2017 +0900 +++ b/.idea/vcs.xml Wed Sep 13 16:29:43 2017 +0900 @@ -2,7 +2,5 @@ <project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="" vcs="hg4idea" /> - <mapping directory="$PROJECT_DIR$/../Alice" vcs="hg4idea" /> - <mapping directory="$PROJECT_DIR$" vcs="hg4idea" /> </component> </project> \ No newline at end of file
--- a/jungle-core.iml Mon Aug 28 17:19:44 2017 +0900 +++ b/jungle-core.iml Wed Sep 13 16:29:43 2017 +0900 @@ -1,12 +1,126 @@ <?xml version="1.0" encoding="UTF-8"?> <module external.linked.project.id="jungle-core" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="cr.ie.u_ryukyu.ac.jp" external.system.module.version="1.1" type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="true"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> + <output url="file://$MODULE_DIR$/build/classes/main" /> + <output-test url="file://$MODULE_DIR$/build/classes/test" /> <exclude-output /> <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> <excludeFolder url="file://$MODULE_DIR$/.gradle" /> <excludeFolder url="file://$MODULE_DIR$/build" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module-library"> + <library name="Gradle: commons-collections:commons-collections:3.2.1"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-collections/commons-collections/3.2.1/761ea405b9b37ced573d2df0d1e3a4e0f9edc668/commons-collections-3.2.1.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-collections/commons-collections/3.2.1/fa095ef874374e5b2a11f8b06c26a5d68c7cb3a4/commons-collections-3.2.1-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: org.apache.maven.surefire:surefire-junit4:2.13"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.maven.surefire/surefire-junit4/2.13/d2a35c1d9af8b40905d6d0cb2c5dc8ff748f8589/surefire-junit4-2.13.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.maven.surefire/surefire-junit4/2.13/fcbb7062f412c1450d86709cb67c4b9261652170/surefire-junit4-2.13-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: com.google.guava:guava:20.0"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/20.0/89507701249388e1ed5ddcf8c41f4ce1be7831ef/guava-20.0.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/20.0/9c8493c7991464839b612d7547d6c263adf08f75/guava-20.0-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: junit:junit:4.11"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/28e0ad201304e4a4abf999ca0570b7cffc352c3c/junit-4.11-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: cr.ie.u_ryukyu.ac.jp:Alice:1.1"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/cr.ie.u_ryukyu.ac.jp/Alice/1.1/c5bad19fa3fb3f79f1775aa22158a200ed7f4d7c/Alice-1.1.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: org.msgpack:msgpack:0.6.12"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.msgpack/msgpack/0.6.12/6a0c88fe022993c490011c3dce7127b29f9a9b3b/msgpack-0.6.12.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.msgpack/msgpack/0.6.12/d884987a52e47f566c6356ce948edbf546616072/msgpack-0.6.12-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: org.apache.maven.surefire:surefire-api:2.13"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.maven.surefire/surefire-api/2.13/4b0223fb338f7f875662497203e9812654e3255c/surefire-api-2.13.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.maven.surefire/surefire-api/2.13/4a1791d8f4e73c797c165e0a11a284a56638675a/surefire-api-2.13-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: org.hamcrest:hamcrest-core:1.3"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b/hamcrest-core-1.3-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: com.googlecode.json-simple:json-simple:1.1.1"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.googlecode.json-simple/json-simple/1.1.1/c9ad4a0850ab676c5c64461a05ca524cdfff59f1/json-simple-1.1.1.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.googlecode.json-simple/json-simple/1.1.1/15bba08e3a239d54b68209c001f9c911559d2fed/json-simple-1.1.1-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library name="Gradle: org.javassist:javassist:3.18.1-GA"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.18.1-GA/d9a09f7732226af26bf99f19e2cffe0ae219db5b/javassist-3.18.1-GA.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.18.1-GA/d8d089f3a8845cce22d3006e02ab1403dd73b5b6/javassist-3.18.1-GA-sources.jar!/" /> + </SOURCES> + </library> + </orderEntry> </component> </module> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/bbs/BBSTest.java Wed Sep 13 16:29:43 2017 +0900 @@ -0,0 +1,185 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.bbs; + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.core.Attributes; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Iterator; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Created by one on 2017/09/13. + */ +public class BBSTest { + + private AtomicInteger requestCounter; + protected Jungle jungle; + protected String _board; + protected String _author; + protected String _message; + protected String _editKey; + + public BBSTest(){ + requestCounter = new AtomicInteger(); + jungle = new DefaultJungle(null, "hoge"); + _board = "Board"; + _author = "Alice"; + _message = "Hello"; + _editKey = "key"; + jungle.createNewTree(_board); + } + + public BBSTest(Jungle jungle){ + requestCounter = new AtomicInteger(); + this.jungle = jungle; + _board = "Board"; + _author = "Alice"; + _message = "Hello"; + _editKey = "key"; + jungle.createNewTree(_board); + } + + public static void main(String args[]){ + BBSTest bbs = new BBSTest(); + bbs.createBoard(); + bbs.createMessage(); + bbs.createMessage(); + + bbs.checkMessage(); + } + + void createBoard(){ + + requestCounter.incrementAndGet(); + JungleTree tree = jungle.getTreeByName(_board); + if (tree == null) { + throw new IllegalStateException(); + } + + Either<Error, JungleTreeEditor> either; + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + do { + + TreeNode node = tree.getRootNode(); + int size = node.getChildren().size(); + DefaultNodePath path = new DefaultNodePath(); + + JungleTreeEditor editor = tree.getJungleTreeEditor(); + either = editor.addNewChildAt(path, size); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + + NodeEditor e = new NodeEditor() { + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, null, new DefaultOperationLog()); + logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); + return DefaultEither.newB(logNode); + } + + @Override + public LoggingNode wrap(TreeNode node,TreeNode node1, OperationLog op) { + return new LoggingNode(node, op); + } + }; + path = path.add(size); + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + } + + void createMessage(){ + requestCounter.incrementAndGet(); + JungleTree tree = jungle.getTreeByName(_board); + if (tree == null) { + throw new IllegalStateException(); + } + + Either<Error, JungleTreeEditor> either; + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + do { + + TreeNode node = tree.getRootNode(); + int size = node.getChildren().size(); + DefaultNodePath path = new DefaultNodePath(); + + JungleTreeEditor editor = tree.getJungleTreeEditor(); + either = editor.addNewChildAt(path, size); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + + NodeEditor e = new NodeEditor() { + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, null, new DefaultOperationLog()); + logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); + return DefaultEither.newB(logNode); + } + + @Override + public LoggingNode wrap(TreeNode node,TreeNode node1, OperationLog op) { + return new LoggingNode(node, op); + } + }; + path = path.add(size); + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + + } + + void checkMessage(){ + JungleTree tree = jungle.getTreeByName(_board); + TreeNode node = tree.getRootNode(); + for (TreeNode child : node.getChildren()){ + TreeNodeAttributes attr = child.getAttributes(); + for (Iterator<String> it = attr.getKeys(); it.hasNext();){ + String key = it.next(); + System.out.print( key + " = "); + try { + System.out.write(attr.get(key).array()); + System.out.print(" "); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println(" "); + } + + + } + } +}