📄 rawpastregrtest.java
字号:
stepDone(); // run replica maintenance runReplicaMaintence(); // Check correct file exists stepStart("Remote Non-Overwriting File Lookup"); local.lookup(remoteId, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Non-Overwriting file should not be null", result != null); assertEquals("Lookup of non-overwriting file should be correct (second) version", newFile, result); stepDone(); sectionDone(); testFetch(); } }); simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } /** * Tests the parameter checking in Past. protected void testParameterChecks() * { final PastImpl local = pasts[environment.getRandomSource().nextInt(NUM_NODES)]; * final Id localId = local.getLocalNodeHandle().getId(); * sectionStart("Parameter Checks Testing"); / Null insert should fail * stepStart("Insertion Of Null"); local.insert(null, new * TestExceptionCommand() { public void receive(Object result) throws * Exception { assertTrue("Exception returned should not be null", result != * null); assertTrue("Exception should be return", result instanceof * Exception); stepDone(); / Null lookup should fail stepStart("Lookup Of * Null"); local.lookup(null, new TestExceptionCommand() { public void * receive(Object result) throws Exception { assertTrue("Exception returned * should not be null", result != null); assertTrue("Exception should be * return", result instanceof Exception); stepDone(); / Null fetch should fail * stepStart("Fetch Of Null"); local.fetch((PastContentHandle) null, new * TestExceptionCommand() { public void receive(Object result) throws * Exception { assertTrue("Exception returned should not be null", result != * null); assertTrue("Exception should be return", result instanceof * Exception); stepDone(); / Null lookup handles should fail stepStart("Lookup * Handles Of Null"); local.lookupHandles(null, 1, new TestExceptionCommand() * { public void receive(Object result) throws Exception { * assertTrue("Exception returned should not be null", result != null); * assertTrue("Exception should be return", result instanceof Exception); * stepDone(); / Lookup handles of -4 should fail stepStart("Lookup Handles Of * -4"); local.lookupHandles(localId, -4, new TestExceptionCommand() { public * void receive(Object result) throws Exception { assertTrue("Exception * returned should not be null", result != null); assertTrue("Exception should * be return", result instanceof Exception); stepDone(); / Lookup handles of 0 * should fail stepStart("Lookup Handles Of 0"); local.lookupHandles(localId, * 0, new TestExceptionCommand() { public void receive(Object result) throws * Exception { assertTrue("Exception returned should not be null", result != * null); assertTrue("Exception should be return", result instanceof * Exception); stepDone(); sectionDone(); testFetch(); } }); simulate(); } }); * simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } }); * simulate(); } */ /** * Tests the fetch function in Past. */ protected void testFetch() { final PastImpl local = pasts[environment.getRandomSource().nextInt(NUM_NODES)]; final PastImpl remote1 = pasts[environment.getRandomSource().nextInt(NUM_NODES)]; PastImpl tmp = pasts[environment.getRandomSource().nextInt(NUM_NODES)]; while (tmp == remote1) { tmp = pasts[environment.getRandomSource().nextInt(NUM_NODES)]; } final PastImpl remote2 = tmp; final Id id = pasts[environment.getRandomSource().nextInt(NUM_NODES)].getLocalNodeHandle().getId(); final PastContent file1 = new VersionedTestPastContent(id, 1); final PastContent file2 = new VersionedTestPastContent(id, 2); final PastContentHandle handle1 = new TestPastContentHandle(remote1, id); final PastContentHandle handle2 = new TestPastContentHandle(remote2, id); sectionStart("Fetch Testing"); // Insert file stepStart("File 1 Insertion"); remote1.getStorageManager().store(id, null, file1, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Storage of file 1 should succeed", ((Boolean) result).booleanValue()); stepDone(); // Insert second file stepStart("File 2 Insertion"); remote2.getStorageManager().store(id, null, file2, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Storage of file 2 should succeed", ((Boolean) result).booleanValue()); stepDone(); // Retrieve first file stepStart("File 1 Fetch"); local.fetch(handle1, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Result should be non-null", result != null); assertEquals("Result should be correct", file1, result); assertTrue("Result should not be file 2", (!file2.equals(result))); final Object received1 = result; stepDone(); // Retrieve second file stepStart("File 2 Fetch"); local.fetch(handle2, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Result should be non-null", result != null); assertEquals("Result should be correct", file2, result); assertTrue("Result should not be file 1", (!file1.equals(result))); final Object received2 = result; stepDone(); // ensure different stepStart("File 1 and 2 Different"); assertTrue("Files should not be equal", (!received1.equals(received2))); stepDone(); // remove file stepStart("File 1 Removal"); remote1.getStorageManager().unstore(id, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Removal of file 1 should succeed", ((Boolean) result).booleanValue()); stepDone(); // remove second file stepStart("File 2 Removal"); remote2.getStorageManager().unstore(id, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Removal of file 2 should succeed", ((Boolean) result).booleanValue()); stepDone(); sectionDone(); testLookupHandles(); } }); simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } /** * Tests the lookup handles function in Past. */ protected void testLookupHandles() { final PastImpl local = pasts[environment.getRandomSource().nextInt(NUM_NODES)]; final PastImpl remote = pasts[environment.getRandomSource().nextInt(NUM_NODES)]; final Id remoteId = remote.getLocalNodeHandle().getId(); final PastContent file = new TestPastContent(remoteId); sectionStart("Lookup Handles Testing"); // Insert file stepStart("File Insertion"); local.insert(file, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Insert of file result should not be null", result != null); assertTrue("Insert of file should return Boolean[]", result instanceof Boolean[]); // assertTrue("Insert of file should return correct sized Boolean[]", (((Boolean[]) result).length == REPLICATION_FACTOR) || // ((NUM_NODES < REPLICATION_FACTOR) && // (((Boolean[]) result).length) == NUM_NODES)); System.out.println("PastRegrTest.testLookupHandles() insert result.length:" + ((Boolean[]) result).length); for (int i = 0; i < ((Boolean[]) result).length; i++) { assertTrue("Insert of file should not return null at replica", ((Boolean[]) result)[i] != null); assertTrue("Insert of file should succeed at replica", ((Boolean[]) result)[i].booleanValue()); } stepDone(); // run replica maintenance runReplicaMaintence(); // Check file exists (at 1 replica) stepStart("Remote Handles Lookup - 1 Replica"); local.lookupHandles(remoteId, 1, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Replicas should not be null", result != null); assertTrue("Replicas should be handle[]", result instanceof PastContentHandle[]); assertTrue("Only 1 replica should be returned", ((PastContentHandle[]) result).length == 1); if (((PastContentHandle[]) result)[0] == null) { System.out.println("PastRegrTest.problem"); } assertEquals("Replica should be for right object", remoteId, ((PastContentHandle[]) result)[0].getId()); stepDone(); // Check file exists (at all replicas) stepStart("Remote Handles Lookup - All Replicas"); local.lookupHandles(remoteId, REPLICATION_FACTOR + 1, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Replicas should not be null", result != null); assertTrue("Replicas should be handle[]", result instanceof PastContentHandle[]); PastContentHandle[] handles = (PastContentHandle[]) result; assertTrue("All replicas should be returned", (handles.length == REPLICATION_FACTOR + 1) || ((NUM_NODES < REPLICATION_FACTOR + 1) && (handles.length) == NUM_NODES)); for (int i = 0; i < handles.length; i++) { assertTrue("Replica " + i + " should not be null", handles[i] != null); assertEquals("Replica " + i + " should be for right object", remoteId, handles[i].getId()); } for (int i = 0; i < handles.length; i++) { for (int j = 0; j < handles.length; j++) { if (i != j) { assertTrue("Handles " + handles[i] + " and " + handles[j] + " should be different", (!handles[i].getNodeHandle().getId().equals(handles[j].getNodeHandle().getId()))); } } } stepDone(); // Check file exists (at a huge number of replicas) stepStart("Remote Handles Lookup - 12 Replicas"); local.lookupHandles(remoteId, 12, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Replicas should not be null", result != null); assertTrue("Replicas should be handle[]", result instanceof PastContentHandle[]); PastContentHandle[] handles = (PastContentHandle[]) result; assertTrue("All replicas should be returned, got " + handles.length, (handles.length >= REPLICATION_FACTOR + 1) || ((NUM_NODES < REPLICATION_FACTOR + 1) && (handles.length) == NUM_NODES)); int count = 0; for (int i = 0; i < handles.length; i++) { if (handles[i] != null) { assertEquals("Replica " + i + " should be for right object", remoteId, handles[i].getId()); count++; } } assertTrue("All replicas should be returned (got " + count + "/" + (REPLICATION_FACTOR + 1) + ")", count == REPLICATION_FACTOR + 1); for (int i = 0; i < handles.length; i++) { for (int j = 0; j < handles.length; j++) { if ((i != j) && (handles[i] != null) && (handles[j] != null)) { assertTrue("Handles " + handles[i] + " and " + handles[j] + " should be different", (!handles[i].getNodeHandle().getId().equals(handles[j].getNodeHandle().getId()))); } } } stepDone(); sectionDone(); testCaching(); } }); simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } /** * Tests the dynamic caching function in Past. */ protected void testCaching() { final PastImpl local = pasts[environment.getRandomSource().nextInt(NUM_NODES)]; final Id id1 = generateId(); final Id id2 = generateId(); final PastContent file1 = new TestPastContent(id1); final PastContent file2 = new TestPastContent(id2); final PastContent file3 = new NonMutableTestPastContent(id2); sectionStart("Caching Testing"); // Manually insert file stepStart("Manually Inserting Object Into Cache"); // check cache local.getStorageManager().getCache().cache(id1, null, file1, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Object should not be null", result != null); assertTrue("Object should be True", result.equals(new Boolean(true))); stepDone(); // Check file exists stepStart("Local Lookup Satisfied by Cache"); local.lookup(id1, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("File should not be null", result != null); assertEquals("Lookup of file should be correct", file1, result);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -