📄 rawpastregrtest.java
字号:
stepDone(); // Insert file stepStart("Caching Mutable Object"); final LookupMessage lmsg = new LookupMessage(1, id2, local.getLocalNodeHandle(), id2); lmsg.receiveResult(file2); assertTrue("Message should continue to be routed", local.forward(new TestRouteMessage(id2, null, lmsg))); stepDone(); stepStart("Cache Shouldn't Contain Object"); // check cache local.getStorageManager().getObject(id2, new TestCommand() { public void receive(Object result) throws Exception { assertTrue("Object should be null", result == null); stepDone(); stepStart("Caching Non-Mutable Object"); lmsg.receiveResult(file3); assertTrue("Message should continue to be routed", local.forward(new TestRouteMessage(id2, null, lmsg))); stepDone(); stepStart("Cache Should Contain Object"); // check cache local.getStorageManager().getObject(id2, new TestCommand() { public void receive(Object result) throws Exception { // assertTrue("Object should not be null", result != null); // assertTrue("Object should be correct", result.equals(file3)); stepDone(); // check lookup LookupMessage lmsg = new LookupMessage(-1, id2, local.getLocalNodeHandle(), id2); stepStart("Lookup Satisfied By Cache"); // assertTrue("Message should not continue to be routed", // ! local.forward(new TestRouteMessage(id2, null, lmsg))); stepDone(); sectionDone(); cleanUp(); } }); simulate(); } }); simulate(); } }); simulate(); } }); simulate(); } /** * Private method which initiates the replica maintenance on all of the nodes */ private void runReplicaMaintence() { for (int i = 0; i < NUM_NODES; i++) { pasts[i].getReplication().replicate(); } simulate(); } /** * Private method which generates a random Id * * @return A new random Id */ private Id generateId() { byte[] data = new byte[20]; environment.getRandomSource().nextBytes(data); return FACTORY.buildId(data); } /** * DESCRIBE THE METHOD */ protected void cleanUp() { running = false; environment.destroy();// synchronized(this) {// this.notifyAll();// } } /** * Usage: DistPastTest [-port p] [-bootstrap host[:port]] [-nodes n] * [-protocol (direct|socket)] [-help] * * @param args DESCRIBE THE PARAMETER * @exception Exception DESCRIBE THE EXCEPTION */ public static void main(String args[]) throws Exception {// System.setOut(new PrintStream(new FileOutputStream("pastrtest.txt")));// System.setErr(System.out);// while(true) { LinkedList delme = new LinkedList(); delme.add(new File("FreePastry-Storage-Root")); while (!delme.isEmpty()) { File f = (File) delme.removeFirst(); if (f.isDirectory()) { File[] subs = f.listFiles(); if (subs.length == 0) { f.delete(); } else { delme.addAll(Arrays.asList(subs)); delme.addLast(f); } } else { f.delete(); } } Environment env = parseArgs(args); env.getParameters().setDouble("p2p_past_successfulInsertThreshold", 1.0); RawPastRegrTest pastTest = new RawPastRegrTest(env); pastTest.start();// synchronized(pastTest) {// pastTest.wait();// }// } } /** * Common superclass for test commands. * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ protected class TestCommand implements Continuation { /** * DESCRIBE THE METHOD * * @param result DESCRIBE THE PARAMETER */ public void receiveResult(Object result) { try { receive(result); } catch (Exception e) { receiveException(e); } } /** * DESCRIBE THE METHOD * * @param result DESCRIBE THE PARAMETER * @exception Exception DESCRIBE THE EXCEPTION */ public void receive(Object result) throws Exception { } /** * DESCRIBE THE METHOD * * @param e DESCRIBE THE PARAMETER */ public void receiveException(Exception e) { stepException(e); } } /** * Common superclass for test commands which should throw an exception * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ protected class TestExceptionCommand implements Continuation { /** * DESCRIBE THE METHOD * * @param result DESCRIBE THE PARAMETER */ public void receiveResult(Object result) { stepDone(FAILURE, "Command should throw an exception - got " + result); } /** * DESCRIBE THE METHOD * * @param result DESCRIBE THE PARAMETER * @exception Exception DESCRIBE THE EXCEPTION */ public void receive(Object result) throws Exception { } /** * DESCRIBE THE METHOD * * @param e DESCRIBE THE PARAMETER */ public void receiveException(Exception e) { try { receive(e); } catch (Exception ex) { receiveException(ex); } } } /** * Utility class for past content objects * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ protected static class TestPastContent implements RawPastContent { /** * DESCRIBE THE FIELD */ protected Id id; /** * DESCRIBE THE FIELD */ protected RawPastContent existing; /** * DESCRIBE THE FIELD */ public final static short TYPE = 1; /** * Constructor for TestPastContent. * * @param id DESCRIBE THE PARAMETER */ public TestPastContent(Id id) { this.id = id; } /** * Constructor for TestPastContent. * * @param buf DESCRIBE THE PARAMETER * @param endpoint DESCRIBE THE PARAMETER * @param pcd DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION */ public TestPastContent(InputBuffer buf, Endpoint endpoint, PastContentDeserializer pcd) throws IOException { id = endpoint.readId(buf, buf.readShort()); if (buf.readBoolean()) { short contentType = buf.readShort(); existing = (RawPastContent) pcd.deserializePastContent(buf, endpoint, contentType); } } /** * Gets the Handle attribute of the TestPastContent object * * @param past DESCRIBE THE PARAMETER * @return The Handle value */ public PastContentHandle getHandle(Past past) { return new TestPastContentHandle(past, id); } /** * Gets the Id attribute of the TestPastContent object * * @return The Id value */ public Id getId() { return id; } /** * Gets the Mutable attribute of the TestPastContent object * * @return The Mutable value */ public boolean isMutable() { return true; } /** * Gets the Type attribute of the TestPastContent object * * @return The Type value */ public short getType() { return TYPE; } /** * DESCRIBE THE METHOD * * @param id DESCRIBE THE PARAMETER * @param existingContent DESCRIBE THE PARAMETER * @return DESCRIBE THE RETURN VALUE * @exception PastException DESCRIBE THE EXCEPTION */ public PastContent checkInsert(Id id, PastContent existingContent) throws PastException { existing = (RawPastContent) existingContent; return this; } /** * DESCRIBE THE METHOD * * @param o DESCRIBE THE PARAMETER * @return DESCRIBE THE RETURN VALUE */ public boolean equals(Object o) { if (!(o instanceof TestPastContent)) { return false; } return ((TestPastContent) o).id.equals(id); } /** * DESCRIBE THE METHOD * * @return DESCRIBE THE RETURN VALUE */ public String toString() { return "TestPastContent(" + id + ")"; } /** * DESCRIBE THE METHOD * * @param buf DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION */ public void serialize(OutputBuffer buf) throws IOException { buf.writeShort(id.getType()); id.serialize(buf); if (existing == null) { buf.writeBoolean(false); } else { buf.writeBoolean(true); buf.writeShort(existing.getType());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -