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); }
/** * Invoke a HelloWorldApp method called sendRndMsg. First choose a random application from * helloClients. */ private void sendRandomMessage() { int n = helloClients.size(); int client = environment.getRandomSource().nextInt(n); HelloWorldApp app = (HelloWorldApp) helloClients.get(client); app.sendRndMsg(environment.getRandomSource()); }