From d889c9bb5da64de7baf5e9b5365bb13d7c810094 Mon Sep 17 00:00:00 2001 From: Ali Younis Date: Tue, 3 Jan 2017 19:14:16 -0800 Subject: [PATCH] Updates --- version2/src/java/iotcloud/CloudComm.java | 1 - version2/src/java/iotcloud/LocalComm.java | 5 +- version2/src/java/iotcloud/Table.java | 106 ++- version2/src/java/iotcloud/Test.java | 962 ++++++++-------------- 4 files changed, 451 insertions(+), 623 deletions(-) diff --git a/version2/src/java/iotcloud/CloudComm.java b/version2/src/java/iotcloud/CloudComm.java index d7a01d6..6f548af 100644 --- a/version2/src/java/iotcloud/CloudComm.java +++ b/version2/src/java/iotcloud/CloudComm.java @@ -111,7 +111,6 @@ class CloudComm { salt = saltTmp; } catch (Exception e) { - e.printStackTrace(); throw new ServerException("Failed setting salt"); } initCrypt(); diff --git a/version2/src/java/iotcloud/LocalComm.java b/version2/src/java/iotcloud/LocalComm.java index d6d3491..d00c473 100644 --- a/version2/src/java/iotcloud/LocalComm.java +++ b/version2/src/java/iotcloud/LocalComm.java @@ -10,12 +10,13 @@ class LocalComm { } public byte[] sendDataToLocalDevice(Long deviceId, byte[] data) { + System.out.println("Passing Locally"); + if (deviceId == t1.getId()) { return t1.localCommInput(data); } else if (deviceId == t2.getId()) { return t2.localCommInput(data); - } - else { + } else { throw new Error("Cannot send to " + deviceId + " using this local comm"); } } diff --git a/version2/src/java/iotcloud/Table.java b/version2/src/java/iotcloud/Table.java index be9defb..1d097c7 100644 --- a/version2/src/java/iotcloud/Table.java +++ b/version2/src/java/iotcloud/Table.java @@ -72,6 +72,7 @@ final public class Table { private List pendingCommitsToDelete = null; private Map localCommunicationChannels; private Map transactionStatusMap = null; + private Map transactionStatusNotSentMap = null; public Table(String hostname, String baseurl, String password, long _localmachineid) { @@ -116,6 +117,7 @@ final public class Table { pendingCommitsToDelete = new LinkedList(); localCommunicationChannels = new HashMap(); transactionStatusMap = new HashMap(); + transactionStatusNotSentMap = new HashMap(); } public void initTable() throws ServerException { @@ -325,10 +327,15 @@ final public class Table { } } - public void update() { + public Pair update() { + + boolean gotLatestFromServer = false; + boolean didSendLocal = false; + try { Slot[] newslots = cloud.getSlots(sequencenumber + 1); validateandupdate(newslots, false); + gotLatestFromServer = true; if (!pendingTransQueue.isEmpty()) { @@ -340,9 +347,61 @@ final public class Table { updateWithNotPendingTrans(); } + didSendLocal = true; + } catch (Exception e) { // could not update so do nothing } + + return new Pair(gotLatestFromServer, didSendLocal); + } + + public Boolean updateFromLocal(long arb) { + LocalComm lc = localCommunicationChannels.get(arb); + if (lc == null) { + // Cant talk directly to arbitrator so cant do anything + return false; + } + + byte[] array = new byte[Long.BYTES ]; + ByteBuffer bbEncode = ByteBuffer.wrap(array); + Long lastSeenCommit = lastCommitSeenSeqNumMap.get(arb); + if (lastSeenCommit != null) { + bbEncode.putLong(lastSeenCommit); + } else { + bbEncode.putLong(0); + } + + byte[] data = lc.sendDataToLocalDevice(arb, bbEncode.array()); + + // Decode the data + ByteBuffer bbDecode = ByteBuffer.wrap(data); + boolean didCommit = bbDecode.get() == 1; + int numberOfCommites = bbDecode.getInt(); + + List newCommits = new LinkedList(); + for (int i = 0; i < numberOfCommites; i++ ) { + bbDecode.get(); + Commit com = (Commit)Commit.decode(null, bbDecode); + newCommits.add(com); + } + + + for (Commit commit : newCommits) { + // Prepare to process the commit + processEntry(commit); + } + + boolean didCommitOrSpeculate = proccessAllNewCommits(); + + // Go through all uncommitted transactions and kill the ones that are dead + deleteDeadUncommittedTransactions(); + + // Speculate on key value pairs + didCommitOrSpeculate |= createSpeculativeTable(); + createPendingTransactionSpeculativeTable(didCommitOrSpeculate); + + return true; } public void startTransaction() { @@ -383,7 +442,7 @@ final public class Table { localTransactionSequenceNumber++; transStatus = new TransactionStatus(TransactionStatus.StatusPending, pendingTransBuild.getArbitrator()); - transactionStatusMap.put(pendingTransBuild.getMachineLocalTransSeqNum(), transStatus); + transactionStatusNotSentMap.put(pendingTransBuild.getMachineLocalTransSeqNum(), transStatus); // Add the pending transaction to the queue pendingTransQueue.add(pendingTransBuild); @@ -467,11 +526,9 @@ final public class Table { sentAllPending = true; } catch (Exception e) { // There was a connection error - e.printStackTrace(); sentAllPending = false; } - if (!sentAllPending) { for (Iterator i = pendingTransQueue.iterator(); i.hasNext(); ) { @@ -507,19 +564,19 @@ final public class Table { didCommitOrSpeculate |= createSpeculativeTable(); createPendingTransactionSpeculativeTable(didCommitOrSpeculate); - if (retData.getFirst()) { - TransactionStatus transStatus = transactionStatusMap.remove(pendingTransBuild.getMachineLocalTransSeqNum()); + TransactionStatus transStatus = transactionStatusNotSentMap.remove(pendingTransBuild.getMachineLocalTransSeqNum()); if (transStatus != null) { transStatus.setStatus(TransactionStatus.StatusCommitted); } } else { - TransactionStatus transStatus = transactionStatusMap.remove(pendingTransBuild.getMachineLocalTransSeqNum()); + TransactionStatus transStatus = transactionStatusNotSentMap.remove(pendingTransBuild.getMachineLocalTransSeqNum()); if (transStatus != null) { transStatus.setStatus(TransactionStatus.StatusAborted); } } + i.remove(); } } } @@ -623,9 +680,12 @@ final public class Table { // Decode the data ByteBuffer bbDecode = ByteBuffer.wrap(data); long lastSeenCommit = bbDecode.getLong(); - bbDecode.get(); - Transaction ut = (Transaction)Transaction.decode(null, bbDecode); + Transaction ut = null; + if (data.length != Long.BYTES) { + bbDecode.get(); + ut = (Transaction)Transaction.decode(null, bbDecode); + } // Do the local update and arbitrate Pair> returnData = doLocalUpdateAndArbitrate(ut, lastSeenCommit); @@ -654,11 +714,6 @@ final public class Table { private Pair> doLocalUpdateAndArbitrate(Transaction ut, Long lastCommitSeen) { - if (ut.getArbitrator() != localmachineid) { - // We are not the arbitrator for that transaction so the other device is talking to the wrong arbitrator - return null; - } - List returnCommits = new ArrayList(); if ((lastCommitSeenSeqNumMap.get(localmachineid) != null) && (lastCommitSeenSeqNumMap.get(localmachineid) > lastCommitSeen)) { @@ -682,6 +737,13 @@ final public class Table { } } + + if ((ut == null) || (ut.getArbitrator() != localmachineid)) { + // We are not the arbitrator for that transaction so the other device is talking to the wrong arbitrator + // or there is no transaction to process + return new Pair>(false, returnCommits); + } + if (!ut.evaluateGuard(commitedTable, null)) { // Guard evaluated as false so return only the commits that the other device has not seen yet return new Pair>(false, returnCommits); @@ -771,7 +833,7 @@ final public class Table { if (sendRetData.getFirst()) { // update the status and change what the sequence number is for the - TransactionStatus transStatus = transactionStatusMap.remove(pendingTrans.getMachineLocalTransSeqNum()); + TransactionStatus transStatus = transactionStatusNotSentMap.remove(pendingTrans.getMachineLocalTransSeqNum()); transStatus.setStatus(TransactionStatus.StatusSent); transStatus.setSentTransaction(); transactionStatusMap.put(trans.getSequenceNumber(), transStatus); @@ -1193,15 +1255,23 @@ final public class Table { // Clear the new commits storage so we can use it later newCommitMap.clear(); + // go through all saved transactions and update the status of those that can be updated for (Iterator> i = transactionStatusMap.entrySet().iterator(); i.hasNext();) { Map.Entry entry = i.next(); long seqnum = entry.getKey(); TransactionStatus status = entry.getValue(); - if ( status.getSentTransaction() && (lastCommitSeenTransSeqNumMap.get(status.getArbitrator()) != null) && (seqnum <= lastCommitSeenTransSeqNumMap.get(status.getArbitrator()))) { - status.setStatus(TransactionStatus.StatusCommitted); - i.remove(); + if (status.getSentTransaction()) { + + Long commitSeqNum = lastCommitSeenTransSeqNumMap.get(status.getArbitrator()); + Long abortSeqNum = lastAbortSeenSeqNumMap.get(status.getArbitrator()); + + if (((commitSeqNum != null) && (seqnum <= commitSeqNum)) || + ((abortSeqNum != null) && (seqnum <= abortSeqNum))) { + status.setStatus(TransactionStatus.StatusCommitted); + i.remove(); + } } } diff --git a/version2/src/java/iotcloud/Test.java b/version2/src/java/iotcloud/Test.java index d2af002..6b0c4ae 100644 --- a/version2/src/java/iotcloud/Test.java +++ b/version2/src/java/iotcloud/Test.java @@ -30,297 +30,20 @@ public class Test { test8(); } else if (args[0].equals("9")) { test9(); + } else if (args[0].equals("10")) { + test10(); + } else if (args[0].equals("11")) { + test11(); } - // else if (args[0].equals("10")) { - // test10(); - // } } - // static void test10() throws ServerException { - - // long startTime = 0; - // long endTime = 0; - // boolean foundError = false; - - // // Setup the 2 clients - // Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); - // t1.initTable(); - // Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); - // t2.update(); - - // if (t1.hasConnection()) { - // System.out.println("Can see server"); - // } - - // LocalComm lc = new LocalComm(t1, t2); - // t1.addLocalComm(t2.getId(), lc); - // t2.addLocalComm(t1.getId(), lc); - - // // Make the Keys - // System.out.println("Setting up keys"); - // startTime = System.currentTimeMillis(); - // for (int i = 0; i < NUMBER_OF_TESTS; i++) { - // String a = "a" + i; - // String b = "b" + i; - // String c = "c" + i; - // String d = "d" + i; - // IoTString ia = new IoTString(a); - // IoTString ib = new IoTString(b); - // IoTString ic = new IoTString(c); - // IoTString id = new IoTString(d); - // t1.createNewKey(ia, 321); - // t1.createNewKey(ib, 351); - // t2.createNewKey(ic, 321); - // t2.createNewKey(id, 351); - // } - // endTime = System.currentTimeMillis(); - // System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); - // System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) ); - // System.out.println(); - - - // // Do Updates for the keys - // System.out.println("Setting Key-Values..."); - // startTime = System.currentTimeMillis(); - // for (int i = 0; i < NUMBER_OF_TESTS; i++) { - // String keyA = "a" + i; - // String keyB = "b" + i; - // String keyC = "c" + i; - // String keyD = "d" + i; - // String valueA = "a" + i; - // String valueB = "b" + i; - // String valueC = "c" + i; - // String valueD = "d" + i; - - // IoTString iKeyA = new IoTString(keyA); - // IoTString iKeyB = new IoTString(keyB); - // IoTString iKeyC = new IoTString(keyC); - // IoTString iKeyD = new IoTString(keyD); - // IoTString iValueA = new IoTString(valueA); - // IoTString iValueB = new IoTString(valueB); - // IoTString iValueC = new IoTString(valueC); - // IoTString iValueD = new IoTString(valueD); - - // while (true) { - // t1.startTransaction(); - // t1.addKV(iKeyA, iValueA); - // if (t1.commitTransactionLocal()) { - // break; - // } - // } - - // while (true) { - // t1.startTransaction(); - // t1.addKV(iKeyB, iValueB); - // if (t1.commitTransactionLocal()) { - // break; - // } - // } - - // while (true) { - // t2.startTransaction(); - // t2.addKV(iKeyC, iValueC); - // if (t2.commitTransactionLocal()) { - // break; - // } - // } - - // while (true) { - // t2.startTransaction(); - // t2.addKV(iKeyD, iValueD); - // if (t2.commitTransactionLocal()) { - // break; - // } - // } - // } - // endTime = System.currentTimeMillis(); - // System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); - // System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) ); - // System.out.println(); - - - // System.out.println("Checking Key-Values..."); - // for (int i = 0; i < NUMBER_OF_TESTS; i++) { - - // String keyA = "a" + i; - // String keyB = "b" + i; - // String keyC = "c" + i; - // String keyD = "d" + i; - // String valueA = "a" + i; - // String valueB = "b" + i; - // String valueC = "c" + i; - // String valueD = "d" + i; - - // IoTString iKeyA = new IoTString(keyA); - // IoTString iKeyB = new IoTString(keyB); - // IoTString iKeyC = new IoTString(keyC); - // IoTString iKeyD = new IoTString(keyD); - // IoTString iValueA = new IoTString(valueA); - // IoTString iValueB = new IoTString(valueB); - // IoTString iValueC = new IoTString(valueC); - // IoTString iValueD = new IoTString(valueD); - - - // IoTString testValA1 = t1.getCommitted(iKeyA); - // IoTString testValB1 = t1.getCommitted(iKeyB); - // IoTString testValC1 = t1.getCommitted(iKeyC); - // IoTString testValD1 = t1.getCommitted(iKeyD); - - // IoTString testValA2 = t2.getCommitted(iKeyA); - // IoTString testValB2 = t2.getCommitted(iKeyB); - // IoTString testValC2 = t2.getCommitted(iKeyC); - // IoTString testValD2 = t2.getCommitted(iKeyD); - - // if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) { - // System.out.println("Key-Value t1 incorrect: " + keyA); - // foundError = true; - // } - - // if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) { - // System.out.println("Key-Value t1 incorrect: " + keyB); - // foundError = true; - // } - - // if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) { - // System.out.println("Key-Value t1 incorrect: " + keyC); - // foundError = true; - // } - - // if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) { - // System.out.println("Key-Value t1 incorrect: " + keyD); - // foundError = true; - // } - - - // if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) { - // System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2); - // foundError = true; - // } - - // if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) { - // System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2); - // foundError = true; - // } - - // if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) { - // System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2); - // foundError = true; - // } - - // if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) { - // System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2); - // foundError = true; - // } - // } - - - // // System.out.println("Updating Clients..."); - // // t1.update(); - // // t2.update(); - // // t1.update(); - // // t2.update(); - - - - // // System.out.println("Checking Key-Values..."); - // // for (int i = 0; i < NUMBER_OF_TESTS; i++) { - - // // String keyA = "a" + i; - // // String keyB = "b" + i; - // // String keyC = "c" + i; - // // String keyD = "d" + i; - // // String valueA = "a" + i; - // // String valueB = "b" + i; - // // String valueC = "c" + i; - // // String valueD = "d" + i; - - // // IoTString iKeyA = new IoTString(keyA); - // // IoTString iKeyB = new IoTString(keyB); - // // IoTString iKeyC = new IoTString(keyC); - // // IoTString iKeyD = new IoTString(keyD); - // // IoTString iValueA = new IoTString(valueA); - // // IoTString iValueB = new IoTString(valueB); - // // IoTString iValueC = new IoTString(valueC); - // // IoTString iValueD = new IoTString(valueD); - - - // // IoTString testValA1 = t1.getCommitted(iKeyA); - // // IoTString testValB1 = t1.getCommitted(iKeyB); - // // IoTString testValC1 = t1.getCommitted(iKeyC); - // // IoTString testValD1 = t1.getCommitted(iKeyD); - - // // IoTString testValA2 = t2.getCommitted(iKeyA); - // // IoTString testValB2 = t2.getCommitted(iKeyB); - // // IoTString testValC2 = t2.getCommitted(iKeyC); - // // IoTString testValD2 = t2.getCommitted(iKeyD); - - // // if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) { - // // System.out.println("Key-Value t1 incorrect: " + keyA); - // // foundError = true; - // // } - - // // if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) { - // // System.out.println("Key-Value t1 incorrect: " + keyB); - // // foundError = true; - // // } - - // // if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) { - // // System.out.println("Key-Value t1 incorrect: " + keyC); - // // foundError = true; - // // } - - // // if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) { - // // System.out.println("Key-Value t1 incorrect: " + keyD); - // // foundError = true; - // // } - - - // // if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) { - // // System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2); - // // foundError = true; - // // } - - // // if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) { - // // System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2); - // // foundError = true; - // // } - - // // if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) { - // // System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2); - // // foundError = true; - // // } - - // // if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) { - // // System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2); - // // foundError = true; - // // } - // // } - - - // if (foundError) { - // System.out.println("Found Errors..."); - // } else { - // System.out.println("No Errors Found..."); - // } - - - // System.out.println(); - // System.out.println(); - // System.out.println(); - // t1.printSlots(); - // System.out.println(); - // System.out.println(); - // t2.printSlots(); - // } - - static void test9() { + static void test11() { boolean foundError = false; // Setup the 2 clients Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); - while (true) { try { t1.initTable(); @@ -329,14 +52,229 @@ public class Test { } Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); + while (t2.update().getFirst() == false) {} + + LocalComm lc = new LocalComm(t1, t2); + t1.addLocalComm(t2.getId(), lc); + t2.addLocalComm(t1.getId(), lc); + + // Make the Keys + System.out.println("Setting up keys"); + for (int i = 0; i < 4; i++) { + String a = "a" + i; + String b = "b" + i; + String c = "c" + i; + String d = "d" + i; + IoTString ia = new IoTString(a); + IoTString ib = new IoTString(b); + IoTString ic = new IoTString(c); + IoTString id = new IoTString(d); + while (true) { + try { + t1.createNewKey(ia, 321); + break; + } catch (Exception e) {} + } + + while (true) { + try { + t1.createNewKey(ib, 351); + break; + } catch (Exception e) {} + } + + while (true) { + try { + t2.createNewKey(ic, 321); + break; + } catch (Exception e) {} + } + + while (true) { + try { + t2.createNewKey(id, 351); + break; + } catch (Exception e) {} + } + } + + // Do Updates for the keys + System.out.println("Setting Key-Values..."); + for (int t = 0; t < NUMBER_OF_TESTS; t++) { + for (int i = 0; i < 4; i++) { + String keyA = "a" + i; + String valueA = "a" + (i + t); + + IoTString iKeyA = new IoTString(keyA); + IoTString iValueA = new IoTString(valueA); + + t1.startTransaction(); + t1.addKV(iKeyA, iValueA); + t1.commitTransaction(); + } + } + + t2.updateFromLocal(321); + System.out.println("Checking Key-Values..."); + for (int i = 0; i < 4; i++) { + + String keyA = "a" + i; + String valueA = "a" + (i + NUMBER_OF_TESTS - 1); + + IoTString iKeyA = new IoTString(keyA); + IoTString iValueA = new IoTString(valueA); + + IoTString testValA1 = t1.getCommitted(iKeyA); + IoTString testValA2 = t2.getCommitted(iKeyA); + + if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) { + System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1 + " " + iValueA); + foundError = true; + } + + if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) { + System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2 + " " + iValueA); + foundError = true; + } + } + + if (foundError) { + System.out.println("Found Errors..."); + } else { + System.out.println("No Errors Found..."); + } + } + + static void test10() { + + boolean foundError = false; + + // Setup the 2 clients + Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); while (true) { try { - t2.update(); + t1.rebuild(); break; } catch (Exception e) {} } + Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); + while (true) { + try { + t2.rebuild(); + break; + } catch (Exception e) {} + } + + LocalComm lc = new LocalComm(t1, t2); + t1.addLocalComm(t2.getId(), lc); + t2.addLocalComm(t1.getId(), lc); + + + System.out.println("Checking Key-Values..."); + for (int i = 0; i < 4; i++) { + + String keyA = "a" + i; + String keyB = "b" + i; + String keyC = "c" + i; + String keyD = "d" + i; + String valueA = "a" + (i + NUMBER_OF_TESTS - 1); + String valueB = "b" + (i + NUMBER_OF_TESTS - 1); + String valueC = "c" + (i + NUMBER_OF_TESTS - 1); + String valueD = "d" + (i + NUMBER_OF_TESTS - 1); + + IoTString iKeyA = new IoTString(keyA); + IoTString iKeyB = new IoTString(keyB); + IoTString iKeyC = new IoTString(keyC); + IoTString iKeyD = new IoTString(keyD); + IoTString iValueA = new IoTString(valueA); + IoTString iValueB = new IoTString(valueB); + IoTString iValueC = new IoTString(valueC); + IoTString iValueD = new IoTString(valueD); + + + IoTString testValA1 = t1.getCommitted(iKeyA); + IoTString testValB1 = t1.getCommitted(iKeyB); + IoTString testValC1 = t1.getCommitted(iKeyC); + IoTString testValD1 = t1.getCommitted(iKeyD); + + IoTString testValA2 = t2.getCommitted(iKeyA); + IoTString testValB2 = t2.getCommitted(iKeyB); + IoTString testValC2 = t2.getCommitted(iKeyC); + IoTString testValD2 = t2.getCommitted(iKeyD); + + if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) { + System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1 + " " + iValueA); + foundError = true; + } + + if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) { + System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1 + " " + iValueB); + foundError = true; + } + + if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) { + System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1 + " " + iValueC); + foundError = true; + } + + if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) { + System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1 + " " + iValueD); + foundError = true; + } + + if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) { + System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2 + " " + iValueA); + foundError = true; + } + + if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) { + System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2 + " " + iValueB); + foundError = true; + } + + if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) { + System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2 + " " + iValueC); + foundError = true; + } + + if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) { + System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2 + " " + iValueD); + foundError = true; + } + } + + if (foundError) { + System.out.println("Found Errors..."); + } else { + System.out.println("No Errors Found..."); + } + } + + static void test9() { + + boolean foundError = false; + List transStatusList = new ArrayList(); + + // Setup the 2 clients + Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); + while (true) { + try { + t1.initTable(); + break; + } catch (Exception e) {} + } + + Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); + while (t2.update().getFirst() == false) {} + + // LocalComm lc = new LocalComm(t1, t2); + // t1.addLocalComm(t2.getId(), lc); + // t2.addLocalComm(t1.getId(), lc); + + + // Make the Keys System.out.println("Setting up keys"); for (int i = 0; i < 4; i++) { @@ -380,7 +318,6 @@ public class Test { // Do Updates for the keys System.out.println("Setting Key-Values..."); - System.out.println("Setting b..."); for (int t = 0; t < NUMBER_OF_TESTS; t++) { for (int i = 0; i < 4; i++) { String keyB = "b" + i; @@ -389,20 +326,17 @@ public class Test { IoTString iKeyB = new IoTString(keyB); IoTString iValueB = new IoTString(valueB); - try { - t1.startTransaction(); - t1.getSpeculativeAtomic(iKeyB); - t1.addKV(iKeyB, iValueB); - t1.commitTransaction(); - System.out.println("Server Success"); - } catch (Exception e) { - System.out.println("Server Fail"); - } + t1.startTransaction(); + t1.getSpeculativeAtomic(iKeyB); + t1.addKV(iKeyB, iValueB); + transStatusList.add(t1.commitTransaction()); } } - System.out.println("Checking b"); + while (t1.update().getFirst() == false) {} + + for (int i = 0; i < 4; i++) { String keyB = "b" + i; @@ -424,7 +358,6 @@ public class Test { } } - System.out.println("Setting c..."); for (int t = 0; t < NUMBER_OF_TESTS; t++) { for (int i = 0; i < 4; i++) { String keyC = "c" + i; @@ -433,20 +366,15 @@ public class Test { IoTString iKeyC = new IoTString(keyC); IoTString iValueC = new IoTString(valueC); - try { - t2.startTransaction(); - t2.getSpeculativeAtomic(iKeyC); - t2.addKV(iKeyC, iValueC); - t2.commitTransaction(); - System.out.println("Server Success"); - } catch (Exception e) { - System.out.println("Server Fail"); - } - + t2.startTransaction(); + t2.getSpeculativeAtomic(iKeyC); + t2.addKV(iKeyC, iValueC); + transStatusList.add(t2.commitTransaction()); } } - System.out.println("Checking c"); + while (t2.update().getFirst() == false) {} + for (int i = 0; i < 4; i++) { String keyC = "c" + i; String valueC = "c" + (i + NUMBER_OF_TESTS - 1); @@ -467,7 +395,6 @@ public class Test { } } - System.out.println("Setting a and b..."); for (int t = 0; t < NUMBER_OF_TESTS; t++) { for (int i = 0; i < 4; i++) { String keyA = "a" + i; @@ -480,101 +407,20 @@ public class Test { IoTString iValueA = new IoTString(valueA); IoTString iValueD = new IoTString(valueD); - try { - t1.startTransaction(); - t1.addKV(iKeyA, iValueA); - t1.commitTransaction(); - System.out.println("Server Success"); - - } catch (Exception e) { - System.out.println("Server Fail"); - } - try { - t2.startTransaction(); - t2.addKV(iKeyD, iValueD); - t2.commitTransaction(); - System.out.println("Server Success"); - - } catch (Exception e) { - System.out.println("Server Fail"); - } + t1.startTransaction(); + t1.addKV(iKeyA, iValueA); + transStatusList.add(t1.commitTransaction()); + t2.startTransaction(); + t2.addKV(iKeyD, iValueD); + transStatusList.add(t2.commitTransaction()); } } System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - System.out.println("Updating Clients..."); - - try { - Thread.sleep(3000); - } catch (Exception e) { - - } - - System.out.println("Updating Clients... T1 first"); - while (true) { - try { - t1.update(); - break; - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Fail"); - } - } - - System.out.println("Updating Clients... T2 first"); - while (true) { - try { - t2.update(); - break; - } catch (Exception e) { - System.out.println("Fail"); - } - } - - System.out.println("Updating Clients... T1 second"); - while (true) { - try { - t1.update(); - break; - } catch (Exception e) { - System.out.println("Fail"); - } - } - - System.out.println("Updating Clients... T2 second"); - while (true) { - try { - t2.update(); - break; - } catch (Exception e) { - System.out.println("Fail"); - } - } + while (t1.update().getFirst() == false) {} + while (t2.update().getFirst() == false) {} System.out.println("Checking Key-Values..."); for (int i = 0; i < 4; i++) { @@ -649,6 +495,13 @@ public class Test { } } + for (TransactionStatus status : transStatusList) { + if (status.getStatus() != TransactionStatus.StatusCommitted) { + foundError = true; + System.out.println(status.getStatus()); + } + } + if (foundError) { System.out.println("Found Errors..."); } else { @@ -657,8 +510,9 @@ public class Test { } static void test8() { - boolean foundError = false; + boolean foundError = false; + List transStatusList = new ArrayList(); // Setup the 2 clients Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); @@ -670,12 +524,11 @@ public class Test { } Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); - while (true) { - try { - t2.update(); - break; - } catch (Exception e) {} - } + while (t2.update().getFirst() == false) {} + + LocalComm lc = new LocalComm(t1, t2); + t1.addLocalComm(t2.getId(), lc); + t2.addLocalComm(t1.getId(), lc); // Make the Keys System.out.println("Setting up keys"); @@ -761,102 +614,58 @@ public class Test { IoTString iValueCPrev = new IoTString(valueCPrev); IoTString iValueDPrev = new IoTString(valueDPrev); - try { - t1.startTransaction(); - if (i != 0) { - IoTString tmp = t1.getSpeculative(iKeyAPrev); - if ((tmp == null) || !tmp.equals(iValueAPrev)) { - System.out.println("Key a Error: " + i); - foundError = true; - } + t1.startTransaction(); + if (i != 0) { + IoTString tmp = t1.getSpeculative(iKeyAPrev); + if ((tmp == null) || !tmp.equals(iValueAPrev)) { + System.out.println("Key a Error: " + i); + foundError = true; } - t1.addKV(iKeyA, iValueA); - t1.commitTransaction(); - } catch (Exception e) { - System.out.println("Connection Failure!"); } + t1.addKV(iKeyA, iValueA); + transStatusList.add(t1.commitTransaction()); - try { - t1.startTransaction(); - if (i != 0) { - IoTString tmp = t1.getSpeculative(iKeyBPrev); - if ((tmp == null) || !tmp.equals(iValueBPrev)) { - System.out.println("Key b Error: " + i); - foundError = true; - } - } - t1.addKV(iKeyB, iValueB); - t1.commitTransaction(); - } catch (Exception e) { - System.out.println("Connection Failure!"); - } - try { - t2.startTransaction(); - if (i != 0) { - IoTString tmp = t2.getSpeculative(iKeyCPrev); - if ((tmp == null) || !tmp.equals(iValueCPrev)) { - System.out.println("Key c Error: " + i); - foundError = true; - } - } - t2.addKV(iKeyC, iValueC); - t2.commitTransaction(); - } catch (Exception e) { - System.out.println("Connection Failure!"); - } - try { - t2.startTransaction(); - if (i != 0) { - IoTString tmp = t2.getSpeculative(iKeyDPrev); - if ((tmp == null) || !tmp.equals(iValueDPrev)) { - System.out.println("Key d Error: " + i); - foundError = true; - } + t1.startTransaction(); + if (i != 0) { + IoTString tmp = t1.getSpeculative(iKeyBPrev); + if ((tmp == null) || !tmp.equals(iValueBPrev)) { + System.out.println("Key b Error: " + i); + foundError = true; } - t2.addKV(iKeyD, iValueD); - t2.commitTransaction(); - } catch (Exception e) { - System.out.println("Connection Failure!"); - } - } - - while (true) { - try { - t1.update(); - break; - } catch (Exception e) { - } - } + t1.addKV(iKeyB, iValueB); + transStatusList.add(t1.commitTransaction()); - while (true) { - try { - t2.update(); - break; - } catch (Exception e) { + t2.startTransaction(); + if (i != 0) { + IoTString tmp = t2.getSpeculative(iKeyCPrev); + if ((tmp == null) || !tmp.equals(iValueCPrev)) { + System.out.println("Key c Error: " + i); + foundError = true; + } } - } - - while (true) { - try { - t1.update(); - break; - } catch (Exception e) { + t2.addKV(iKeyC, iValueC); + transStatusList.add(t2.commitTransaction()); + t2.startTransaction(); + if (i != 0) { + IoTString tmp = t2.getSpeculative(iKeyDPrev); + if ((tmp == null) || !tmp.equals(iValueDPrev)) { + System.out.println("Key d Error: " + i); + foundError = true; + } } + t2.addKV(iKeyD, iValueD); + transStatusList.add(t2.commitTransaction()); } - while (true) { - try { - t2.update(); - break; - } catch (Exception e) { - } - } + System.out.println("Updating..."); + while (t1.update().getFirst() == false) {} + while (t2.update().getFirst() == false) {} System.out.println("Checking Key-Values..."); @@ -933,6 +742,11 @@ public class Test { } } + for (TransactionStatus status : transStatusList) { + if (status.getStatus() != TransactionStatus.StatusCommitted) { + foundError = true; + } + } if (foundError) { System.out.println("Found Errors..."); } else { @@ -942,9 +756,8 @@ public class Test { static void test7() throws ServerException { - long startTime = 0; - long endTime = 0; boolean foundError = false; + List transStatusList = new ArrayList(); // Setup the 2 clients Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); @@ -952,7 +765,6 @@ public class Test { Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); t2.update(); - startTime = System.currentTimeMillis(); // Make the Keys System.out.println("Setting up keys"); for (int i = 0; i < 4; i++) { @@ -969,16 +781,10 @@ public class Test { t2.createNewKey(ic, 321); t2.createNewKey(id, 351); } - endTime = System.currentTimeMillis(); - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); - System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (4)) ); - System.out.println(); // Do Updates for the keys System.out.println("Setting Key-Values..."); - startTime = System.currentTimeMillis(); - System.out.println("Setting b..."); for (int t = 0; t < NUMBER_OF_TESTS; t++) { for (int i = 0; i < 4; i++) { String keyB = "b" + i; @@ -990,17 +796,10 @@ public class Test { t1.startTransaction(); t1.getSpeculativeAtomic(iKeyB); t1.addKV(iKeyB, iValueB); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); } } - endTime = System.currentTimeMillis(); - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); - System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (4 * NUMBER_OF_TESTS)) ); - System.out.println(); - - - System.out.println("Checking b"); for (int i = 0; i < 4; i++) { String keyB = "b" + i; @@ -1022,8 +821,6 @@ public class Test { } } - startTime = System.currentTimeMillis(); - System.out.println("Setting c..."); for (int t = 0; t < NUMBER_OF_TESTS; t++) { for (int i = 0; i < 4; i++) { String keyC = "c" + i; @@ -1035,16 +832,10 @@ public class Test { t2.startTransaction(); t2.getSpeculativeAtomic(iKeyC); t2.addKV(iKeyC, iValueC); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); } } - endTime = System.currentTimeMillis(); - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); - System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (4 * NUMBER_OF_TESTS)) ); - System.out.println(); - - System.out.println("Checking c"); for (int i = 0; i < 4; i++) { String keyC = "c" + i; String valueC = "c" + (i + NUMBER_OF_TESTS - 1); @@ -1065,7 +856,6 @@ public class Test { } } - System.out.println("Setting a and b..."); for (int t = 0; t < NUMBER_OF_TESTS; t++) { for (int i = 0; i < 4; i++) { String keyA = "a" + i; @@ -1080,11 +870,11 @@ public class Test { t1.startTransaction(); t1.addKV(iKeyA, iValueA); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); t2.startTransaction(); t2.addKV(iKeyD, iValueD); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); } } @@ -1167,6 +957,12 @@ public class Test { } } + for (TransactionStatus status : transStatusList) { + if (status.getStatus() != TransactionStatus.StatusCommitted) { + foundError = true; + } + } + if (foundError) { System.out.println("Found Errors..."); } else { @@ -1174,9 +970,10 @@ public class Test { } } - static void test6() throws ServerException { - long startTime = 0; - long endTime = 0; + static void test6() throws ServerException { + + boolean foundError = false; + List transStatusList = new ArrayList(); // Setup the 2 clients Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); @@ -1184,10 +981,8 @@ public class Test { Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); t2.update(); - // Make the Keys System.out.println("Setting up keys"); - startTime = System.currentTimeMillis(); for (int i = 0; i < NUMBER_OF_TESTS; i++) { String a = "a" + i; String b = "b" + i; @@ -1202,18 +997,9 @@ public class Test { t2.createNewKey(ic, 321); t2.createNewKey(id, 351); } - endTime = System.currentTimeMillis(); - - - - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); - System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) ); - System.out.println(); - // Do Updates for the keys System.out.println("Setting Key-Values..."); - startTime = System.currentTimeMillis(); for (int i = 0; i < NUMBER_OF_TESTS; i++) { String keyA = "a" + i; String keyB = "b" + i; @@ -1236,37 +1022,27 @@ public class Test { t1.startTransaction(); t1.getCommittedAtomic(iKeyA); t1.addKV(iKeyA, iValueA); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); t1.startTransaction(); t1.getCommittedAtomic(iKeyB); t1.addKV(iKeyB, iValueB); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); t2.startTransaction(); t2.getCommittedAtomic(iKeyC); t2.addKV(iKeyC, iValueC); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); t2.startTransaction(); t2.getCommittedAtomic(iKeyD); t2.addKV(iKeyD, iValueD); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); } - endTime = System.currentTimeMillis(); - - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); - System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) ); - System.out.println(); - System.out.println("Updating Clients..."); t1.update(); t2.update(); - t1.update(); - t2.update(); - - boolean foundError = false; System.out.println("Checking Key-Values..."); for (int i = 0; i < NUMBER_OF_TESTS; i++) { @@ -1342,27 +1118,23 @@ public class Test { } } + for (TransactionStatus status : transStatusList) { + if (status.getStatus() != TransactionStatus.StatusCommitted) { + foundError = true; + } + } + if (foundError) { System.out.println("Found Errors..."); } else { System.out.println("No Errors Found..."); } - - // System.out.println(); - // System.out.println(); - // System.out.println(); - // t1.printSlots(); - // System.out.println(); - // System.out.println(); - // System.out.println(); - // t2.printSlots(); } static void test5() throws ServerException { - long startTime = 0; - long endTime = 0; boolean foundError = false; + List transStatusList = new ArrayList(); // Setup the 2 clients Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); @@ -1387,14 +1159,6 @@ public class Test { t2.createNewKey(ic, 321); t2.createNewKey(id, 351); } - endTime = System.currentTimeMillis(); - - - - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); - System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (4)) ); - System.out.println(); - // Do Updates for the keys System.out.println("Setting Key-Values..."); @@ -1409,7 +1173,7 @@ public class Test { t1.startTransaction(); t1.addKV(iKeyB, iValueB); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); } } @@ -1444,7 +1208,7 @@ public class Test { t2.startTransaction(); t2.addKV(iKeyC, iValueC); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); } } @@ -1482,19 +1246,17 @@ public class Test { t1.startTransaction(); t1.addKV(iKeyA, iValueA); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); t2.startTransaction(); t2.addKV(iKeyD, iValueD); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); } } System.out.println("Updating Clients..."); t1.update(); t2.update(); - t1.update(); - t2.update(); System.out.println("Checking Key-Values..."); @@ -1571,6 +1333,12 @@ public class Test { } } + for (TransactionStatus status : transStatusList) { + if (status.getStatus() != TransactionStatus.StatusCommitted) { + foundError = true; + } + } + if (foundError) { System.out.println("Found Errors..."); } else { @@ -1580,8 +1348,10 @@ public class Test { static void test4() throws ServerException { + boolean foundError = false; long startTime = 0; long endTime = 0; + List transStatusList = new ArrayList(); // Setup the 2 clients Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); @@ -1589,7 +1359,6 @@ public class Test { Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); t2.update(); - // Make the Keys System.out.println("Setting up keys"); startTime = System.currentTimeMillis(); @@ -1608,9 +1377,6 @@ public class Test { t2.createNewKey(id, 351); } endTime = System.currentTimeMillis(); - - - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) ); System.out.println(); @@ -1641,23 +1407,22 @@ public class Test { t1.startTransaction(); t1.addKV(iKeyA, iValueA); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); t1.startTransaction(); t1.addKV(iKeyB, iValueB); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); t2.startTransaction(); t2.addKV(iKeyC, iValueC); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); t2.startTransaction(); t2.addKV(iKeyD, iValueD); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); } } endTime = System.currentTimeMillis(); - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 16)) ); System.out.println(); @@ -1666,10 +1431,7 @@ public class Test { System.out.println("Updating Clients..."); t1.update(); t2.update(); - t1.update(); - t2.update(); - boolean foundError = false; System.out.println("Checking Key-Values..."); for (int i = 0; i < 4; i++) { @@ -1745,6 +1507,12 @@ public class Test { } } + for (TransactionStatus status : transStatusList) { + if (status.getStatus() != TransactionStatus.StatusCommitted) { + foundError = true; + } + } + if (foundError) { System.out.println("Found Errors..."); } else { @@ -1758,6 +1526,8 @@ public class Test { long endTime = 0; boolean foundError = false; + List transStatusList = new ArrayList(); + // Setup the 2 clients Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); t1.initTable(); @@ -1783,9 +1553,6 @@ public class Test { t2.createNewKey(id, 351); } endTime = System.currentTimeMillis(); - - - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) ); System.out.println(); @@ -1803,7 +1570,7 @@ public class Test { t1.startTransaction(); t1.addKV(iKeyB, iValueB); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); } for (int i = 0; i < NUMBER_OF_TESTS; i++) { @@ -1815,7 +1582,7 @@ public class Test { t2.startTransaction(); t2.addKV(iKeyC, iValueC); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); } for (int i = 0; i < NUMBER_OF_TESTS; i++) { @@ -1831,14 +1598,13 @@ public class Test { t1.startTransaction(); t1.addKV(iKeyA, iValueA); - t1.commitTransaction(); + transStatusList.add(t1.commitTransaction()); t2.startTransaction(); t2.addKV(iKeyD, iValueD); - t2.commitTransaction(); + transStatusList.add(t2.commitTransaction()); } endTime = System.currentTimeMillis(); - System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) ); System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) ); System.out.println(); @@ -1847,8 +1613,6 @@ public class Test { System.out.println("Updating Clients..."); t1.update(); t2.update(); - t1.update(); - t2.update(); System.out.println("Checking Key-Values..."); @@ -1925,6 +1689,12 @@ public class Test { } } + for (TransactionStatus status : transStatusList) { + if (status.getStatus() != TransactionStatus.StatusCommitted) { + foundError = true; + } + } + if (foundError) { System.out.println("Found Errors..."); } else { @@ -1934,8 +1704,10 @@ public class Test { static void test2() throws ServerException { + boolean foundError = false; long startTime = 0; long endTime = 0; + List transStatusList = new ArrayList(); // Setup the 2 clients Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321); @@ -1943,7 +1715,6 @@ public class Test { Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351); t2.update(); - List transStatusList = new ArrayList(); // Make the Keys System.out.println("Setting up keys"); @@ -1967,7 +1738,6 @@ public class Test { System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) ); System.out.println(); - // Do Updates for the keys System.out.println("Setting Key-Values..."); startTime = System.currentTimeMillis(); @@ -2015,10 +1785,7 @@ public class Test { System.out.println("Updating Clients..."); t1.update(); t2.update(); - t1.update(); - t2.update(); - boolean foundError = false; System.out.println("Checking Key-Values..."); for (int i = 0; i < NUMBER_OF_TESTS; i++) { @@ -2105,14 +1872,5 @@ public class Test { } else { System.out.println("No Errors Found..."); } - - - System.out.println(); - System.out.println(); - System.out.println(); - t1.printSlots(); - System.out.println(); - System.out.println(); - t2.printSlots(); } } -- 2.34.1