Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 357:f9346cd6ef92
get timestamp
author | nozomi |
---|---|
date | Thu, 12 Oct 2017 16:14:52 +0900 |
parents | 97a09cc105d9 |
children | e13af3fd64cf |
files | src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/bbs/BBSTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/logupdate/LogupdateTestStartCodeSegment.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/logupdate/Logupdator.java |
diffstat | 3 files changed, 54 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/bbs/BBSTest.java Wed Oct 11 17:15:33 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/bbs/BBSTest.java Thu Oct 12 16:14:52 2017 +0900 @@ -2,7 +2,6 @@ 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; @@ -32,6 +31,7 @@ protected String _author; protected String _message; protected String _editKey; + protected String host; public BBSTest(){ requestCounter = new AtomicInteger(); @@ -43,13 +43,14 @@ jungle.createNewTree(_board); } - public BBSTest(Jungle jungle){ + public BBSTest(Jungle jungle, String host){ requestCounter = new AtomicInteger(); this.jungle = jungle; _board = "Board"; _author = "Alice"; _message = "Hello"; _editKey = "key"; + this.host = host; jungle.createNewTree(_board); } @@ -57,7 +58,11 @@ BBSTest bbs = new BBSTest(); bbs.createMessage(); - bbs.checkMessage(); + try { + bbs.checkMessage(); + } catch (IOException e) { + e.printStackTrace(); + } } public void createMessage(){ @@ -69,8 +74,8 @@ Either<Error, JungleTreeEditor> either; final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); + final ByteBuffer tBuffer = ByteBuffer.allocate(Long.BYTES); + tBuffer.putLong(0, timestamp); do { TreeNode node = tree.getRootNode(); @@ -112,7 +117,7 @@ } static int checkCount = 0; - public void checkMessage() { + public void checkMessage() throws IOException { System.out.println("checkMessage: " + checkCount ++); JungleTree tree = jungle.getTreeByName(_board); TreeNode node = tree.getRootNode(); @@ -121,22 +126,41 @@ for (Iterator<String> it = attr.getKeys(); it.hasNext();){ String key = it.next(); System.out.print( key + " = "); - try { - if (key.equals("timestamp")) { - long timestamp = ByteBuffer.wrap(attr.get(key).array()).getLong(); - System.out.write((int)timestamp); - } - else { - System.out.write(attr.get(key).array()); - } - System.out.print(" "); - } catch (IOException e) { - e.printStackTrace(); + if (key.equals("timestamp")) { + ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); + buffer.put(attr.get(key).array(), 0, attr.get(key).array().length); + buffer.flip();//need flip + long timestamp = buffer.getLong(); + System.out.print(String.valueOf(timestamp)); } + else { + System.out.write(attr.get(key).array()); + } + System.out.print(" "); System.out.println(" "); } System.out.println(" "); + } + } + public void checkTime() throws IOException { + System.out.println("hostname: " + host); + 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(); + if (key.equals("timestamp")) { + System.out.print( key + " = "); + ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); + buffer.put(attr.get(key).array(), 0, attr.get(key).array().length); + buffer.flip();//need flip + long timestamp = buffer.getLong(); + System.out.print(String.valueOf(System.currentTimeMillis() - timestamp)); + } + } + System.out.println(" "); } }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/logupdate/LogupdateTestStartCodeSegment.java Wed Oct 11 17:15:33 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/logupdate/LogupdateTestStartCodeSegment.java Thu Oct 12 16:14:52 2017 +0900 @@ -10,6 +10,7 @@ import jp.ac.u_ryukyu.ie.cr.jungleNetwork.core.NetworkDefaultJungle; import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.AliceJournal; +import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -43,7 +44,7 @@ if (arg.equals("-persistent")) { persistentFlag = true; } - BBSTest bbsTest = new BBSTest(new NetworkDefaultJungle(new AliceJournal(), "hoge")); + BBSTest bbsTest = new BBSTest(new NetworkDefaultJungle(new AliceJournal(), "hoge"), host.asString()); Logupdator cassaBBS = new Logupdator(name, bbsTest); cassaBBS.init(); ods.put("updator", cassaBBS); @@ -51,7 +52,11 @@ new LogUpdateCodeSegment(); if (config.isWriteMode()){ bbsTest.createMessage(); - bbsTest.checkMessage(); + try { + bbsTest.checkTime(); + } catch (IOException e) { + e.printStackTrace(); + } } } }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/logupdate/Logupdator.java Wed Oct 11 17:15:33 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/logupdate/Logupdator.java Thu Oct 12 16:14:52 2017 +0900 @@ -12,6 +12,7 @@ import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.JungleUpdater; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicInteger; @@ -68,7 +69,11 @@ either = editor.success(); } while(either.isA()); requestIncrementAndGet(); - bbsTest.checkMessage(); + try { + bbsTest.checkTime(); + } catch (IOException e) { + e.printStackTrace(); + } return either; }