/** * @param millisToFinish Call finish() after this amount of time * @throws Exception */ public PRRegressionTest(int millisToFinish) throws Exception { env = RecordLayer.generateEnvironment(); // new Environment(); env.getSelectorManager() .schedule( new TimerTask() { @Override public void run() { finish(); } }, millisToFinish); logger = env.getLogManager().getLogger(PRRegressionTest.class, null); setLoggingParams(env); buildCryptoMaterial(env); env.getSelectorManager() .invoke( new Runnable() { public void run() { try { buildPlayers(env); setupWitnesses(); } catch (Exception ioe) { env.destroy(); throw new RuntimeException(ioe); } } }); }
public Player(HandleImpl localHandle, HandleImpl dstHandle, final Environment env2) throws Exception { super(); this.destHandle = dstHandle; // this.id = id; env = cloneEnvironment(env2, localHandle.name, localHandle.id.id); this.logger = env.getLogManager().getLogger(Player.class, null); File f = new File(localHandle.name); if (f.exists()) { File f2 = new File(f, "peers"); File[] foo = f2.listFiles(); if (foo != null) { for (int c = 0; c < foo.length; c++) { foo[c].delete(); } } foo = f.listFiles(); if (foo != null) { for (int c = 0; c < foo.length; c++) { foo[c].delete(); } } // System.out.println("Delete "+f+","+f.delete()); } // File f = new File(name+".data"); // if (f.exists()) f.delete(); // f = new File(name+".index"); // if (f.exists()) f.delete(); this.localHandle = localHandle; playerTable.put(localHandle, this); pair = keyPairGen.generateKeyPair(); cert = caTool.sign(localHandle.name, pair.getPublic()); t1 = getTL(); transport = getIdTransport(); idTLTable.put(localHandle, transport); pr = getPeerReview(this, transport, env); app = getApp(); pr.setApp(app); env.getSelectorManager() .invoke( new Runnable() { public void run() { try { pr.init(Player.this.localHandle.name); } catch (IOException ioe) { ioe.printStackTrace(); env2.destroy(); } } }); }
public BogusApp(Player player, TransportLayer<HandleImpl, ByteBuffer> tl, Environment env) { super(); this.player = player; this.tl = tl; this.env = env; this.logger = env.getLogManager().getLogger(BogusApp.class, null); logger.log("new bogus app " + player); dest = player.destHandle; tl.setCallback(this); }
/** * @param wtl * @param env * @param errorHandler call me when there is a problem * @param header the header to expect from a socket/packet * @param timeOut how long to wait before killing a socket that is not sending (milliseconds) */ public MagicNumberTransportLayer( TransportLayer<Identifier, ByteBuffer> wtl, Environment env, ErrorHandler<Identifier> errorHandler, byte[] header, int timeOut) { this.logger = env.getLogManager().getLogger(MagicNumberTransportLayer.class, null); this.environment = env; this.wire = wtl; this.HEADER = header; this.SOCKET_TIMEOUT = timeOut; this.errorHandler = errorHandler; this.callback = new DefaultCallback<Identifier, ByteBuffer>(logger); if (this.errorHandler == null) { this.errorHandler = new DefaultErrorHandler<Identifier>(logger); } wire.setCallback(this); }
public Replayer( final Id id, final InetSocketAddress addr, InetSocketAddress bootaddress, final long startTime, final long randSeed) throws Exception { this.bootaddress = bootaddress; Environment env = ReplayLayer.generateEnvironment(id.toString(), startTime, randSeed, null); final Parameters params = env.getParameters(); params.setInt( "pastry_socket_scm_max_open_sockets", params.getInt( "org.mpisws.p2p.testing.transportlayer.replay_pastry_socket_scm_max_open_sockets")); params.setBoolean("pastry_socket_use_own_random", false); // env.getParameters().setInt("rice.environment.random_loglevel", Logger.FINER); logger = env.getLogManager().getLogger(Replayer.class, null); // env.getParameters().setInt("org.mpisws.p2p.transport.peerreview.replay_loglevel", // Logger.FINER); final Logger simLogger = env.getLogManager().getLogger(EventSimulator.class, null); final List<ReplayLayer<InetSocketAddress>> replayers = new ArrayList<ReplayLayer<InetSocketAddress>>(); SocketPastryNodeFactory factory = new SocketPastryNodeFactory( new NodeIdFactory() { public Id generateNodeId() { return id; } }, addr.getPort(), env) { // @Override // protected TransportLayer<MultiInetSocketAddress, ByteBuffer> // getPriorityTransportLayer(TransportLayer<MultiInetSocketAddress, ByteBuffer> trans, // LivenessProvider<MultiInetSocketAddress> liveness, // ProximityProvider<MultiInetSocketAddress> prox, PastryNode pn) { // // get rid of the priorityLayer // if // (params.getBoolean("org.mpisws.p2p.testing.transportlayer.replay.use_priority")) { // return super.getPriorityTransportLayer(trans, liveness, prox, pn); // } else { // return trans; // } // } @Override public NodeHandle getLocalHandle(PastryNode pn, NodeHandleFactory nhf) { SocketNodeHandle ret = (SocketNodeHandle) super.getLocalHandle(pn, nhf); logger.log(ret.toStringFull()); return ret; } @Override protected RandomSource cloneRandomSource( Environment rootEnvironment, Id nodeId, LogManager lman) { return rootEnvironment.getRandomSource(); } @Override protected TransportLayer<InetSocketAddress, ByteBuffer> getWireTransportLayer( InetSocketAddress innermostAddress, PastryNode pn) throws IOException { Serializer<InetSocketAddress> serializer = new InetSocketAddressSerializer(); HashProvider hashProv = new NullHashProvider(); SecureHistoryFactory shFactory = new SecureHistoryFactoryImpl(hashProv, pn.getEnvironment()); String logName = "0x" + id.toStringFull().substring(0, 6); SecureHistory hist = shFactory.open(logName, "r"); ReplayLayer<InetSocketAddress> replay = new ReplayLayer<InetSocketAddress>( serializer, hashProv, hist, addr, pn.getEnvironment()); replay.registerEvent(Replayer.this, EVT_BOOT, EVT_SUBSCRIBE, EVT_PUBLISH); replayers.add(replay); return replay; } }; // construct a node, passing the null boothandle on the first loop will // cause the node to start its own ring node = (PastryNode) factory.newNode(); app = new MyScribeClient(node); ReplaySM sim = (ReplaySM) env.getSelectorManager(); ReplayLayer<InetSocketAddress> replay = replayers.get(0); replay.makeProgress(); // get rid of INIT event sim.setVerifier(replay); sim.start(); // // this is an example of th enew way // //PastryNode node = factory.newNode(nidFactory.generateNodeId()); // //node.getBootstrapper().boot(Collections.singleton(bootaddress)); // // // the node may require sending several messages to fully boot into the ring // synchronized(node) { // while(!node.isReady() && !node.joinFailed()) { // // delay so we don't busy-wait // node.wait(500); // // // abort if can't join // if (node.joinFailed()) { // throw new IOException("Could not join the FreePastry ring. // Reason:"+node.joinFailedReason()); // } // } // } // // System.out.println("Finished creating new node: " + node); // // // construct a new scribe application // MyScribeClient app = new MyScribeClient(node); // // // for all the rest just subscribe // app.subscribe(); // now, print the tree // env.getTimeSource().sleep(5000); try { env.getTimeSource().sleep(55000); } catch (InterruptedException ie) { return; } env.destroy(); }
public void init() { invokedInsert = false; messageId = Id.build("1111567890123456789012345678901234560023"); content = new KoalaPiEntityContent( messageId, "what", false, "type", 4, NodeScope.AVAILABILITY_ZONE, "url", 1); continuation = mock(Continuation.class); builder = mock(MessageBuilder.class); when(builder.buildMessage()) .thenReturn(new GCInsertMessage(-1, content, 0L, nodeHandle, Id.build("dest"))); Logger logger = mock(Logger.class); LogManager logManager = mock(LogManager.class); when(logManager.getLogger(isA(Class.class), eq(instance))).thenReturn(logger); Parameters parameters = mock(Parameters.class); RandomSource randomSource = mock(RandomSource.class); Environment environment = mock(Environment.class); when(environment.getLogManager()).thenReturn(logManager); when(environment.getParameters()).thenReturn(parameters); when(environment.getRandomSource()).thenReturn(randomSource); TimeSource timesource = mock(TimeSource.class); when(timesource.currentTimeMillis()).thenReturn(System.currentTimeMillis()); when(environment.getTimeSource()).thenReturn(timesource); Endpoint endpoint = mock(Endpoint.class); doAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { koalaDeserializer = (MessageDeserializer) invocation.getArguments()[0]; return null; } }) .when(endpoint) .setDeserializer(isA(MessageDeserializer.class)); koalaIdFactory = mock(KoalaIdFactory.class); when(koalaIdFactory.buildIdFromToString(anyString())) .thenAnswer( new Answer<Id>() { @Override public Id answer(InvocationOnMock invocation) throws Throwable { return Id.build((String) invocation.getArguments()[0]); } }); when(koalaIdFactory.buildId(anyString())) .thenAnswer( new Answer<Id>() { @Override public Id answer(InvocationOnMock invocation) throws Throwable { return Id.build((String) invocation.getArguments()[0]); } }); node = mock(PastryNode.class); when(node.getEnvironment()).thenReturn(environment); when(node.buildEndpoint(isA(Application.class), eq(instance))).thenReturn(endpoint); when(node.getIdFactory()).thenReturn(koalaIdFactory); sentBackupContent = new ArrayList<KoalaMutableContent>(); backupIds = new HashSet<rice.p2p.commonapi.Id>(); storageManager = mock(StorageManager.class); koalaPiEntityFactory = mock(KoalaPiEntityFactory.class); }