@Test public void testGetRegionalIds() { // setup KoalaIdFactory koalaIdFactory = new KoalaIdFactory(0, 0); koalaIdFactory.setKoalaPiEntityFactory(koalaPiEntityFactory); koalaGCPastImpl.setKoalaIdFactory(koalaIdFactory); PId testId = koalaGCPastImpl.getKoalaIdFactory().buildPId("R. Lopez"); // act Set<String> ids = koalaGCPastImpl.generateBackupIds(4, NodeScope.REGION, testId); assertEquals(4, ids.size()); assertSetEndsWithBackupIdentifier(ids); assertSetContains(ids, testId.getIdAsHex().substring(4, testId.getIdAsHex().length() - 1)); }
@Test public void testGetGlobalIds() { // setup KoalaIdFactory koalaIdFactory = new KoalaIdFactory(0, 0); koalaIdFactory.setKoalaPiEntityFactory(koalaPiEntityFactory); koalaGCPastImpl.setKoalaIdFactory(koalaIdFactory); PId testId = koalaGCPastImpl.getKoalaIdFactory().buildPId("R. Lopez"); // act Set<String> globalIds = koalaGCPastImpl.generateBackupIds(4, NodeScope.GLOBAL, testId); // asssert assertEquals(4, globalIds.size()); assertSetEndsWithBackupIdentifier(globalIds); }
@Test public void testBackupContent() { // setup PId pid = mock(PId.class); when(pid.asBackupId()).thenReturn(pid); when(pid.getIdAsHex()).thenReturn(content.getId().toStringFull()); when(koalaIdFactory.convertToPId(eq(content.getId()))).thenReturn(pid); // act koalaGCPastImpl.backupContent(4, NodeScope.REGION, content); // assert assertEquals(4, backupIds.size()); for (KoalaMutableContent sentContent : sentBackupContent) { assertEquals(sentContent.getBody(), content.getBody()); assertEquals( sentContent.getContentHeaders().get(DhtContentHeader.CONTENT_TYPE), content.getContentHeaders().get(DhtContentHeader.CONTENT_TYPE)); assertEquals( sentContent.getContentHeaders().get(DhtContentHeader.ID), sentContent.getId().toStringFull()); assertEquals(sentContent.getVersion(), content.getVersion()); assertNotSame(sentContent.getId(), content.getId()); } }
@Test public void testGetAvailabilityZoneIds() { // setup KoalaIdFactory koalaIdFactory = new KoalaIdFactory(0, 0); koalaIdFactory.setKoalaPiEntityFactory(koalaPiEntityFactory); koalaGCPastImpl.setKoalaIdFactory(koalaIdFactory); PId testId = koalaGCPastImpl.getKoalaIdFactory().buildPId("YEAHBOB"); // act Set<String> ids = koalaGCPastImpl.generateBackupIds(4, NodeScope.AVAILABILITY_ZONE, testId); // assert assertEquals(4, ids.size()); assertSetEndsWithBackupIdentifier(ids); assertSetContains(ids, testId.getIdAsHex().substring(5, testId.getIdAsHex().length() - 1)); }
@Test public void testDeliverFetchHandleMessage() { // setup Id id = mock(Id.class); FetchHandleMessage message = mock(FetchHandleMessage.class); when(message.getId()).thenReturn(id); PId pid = mock(PId.class); when(koalaIdFactory.convertToPId(id)).thenReturn(pid); when(pid.forDht()).thenReturn(pid); when(koalaIdFactory.buildId(pid)).thenReturn(id); // act koalaGCPastImpl.deliver(null, message); // assert verify(storageManager).getObject(eq(id), isA(Continuation.class)); }
@Before public void before() { when(koalaIdFactory.buildPId(eq(nodeIdStr))).thenReturn(nodeId); doAnswer( new Answer<PId>() { @Override public PId answer(InvocationOnMock invocation) throws Throwable { String id = (String) invocation.getArguments()[0]; if (id.equals(Instance.getUrl("i-123"))) return id123; if (id.equals(Instance.getUrl("i-456"))) return id456; return null; } }) .when(koalaIdFactory) .buildId(isA(String.class)); when(piIdBuilder.getPIdForEc2AvailabilityZone(anyString())).thenReturn(id123).thenReturn(id456); when(apiApplicationManager.newMessageContext()) .thenReturn(instanceManagerMessageContext) .thenReturn(secondMessageContext); when(apiApplicationManager.getKoalaIdFactory()).thenReturn(koalaIdFactory); AvailabilityZones zones = new AvailabilityZones(); zones.addAvailabilityZone( new AvailabilityZone( AVAILABILITY_ZONE_1_NAME, AVAILABILITY_ZONE_1_CODE, REGION_ZONE_1_CODE, AVAILABILITY_ZONE_1_NAME)); when(apiApplicationManager.getAvailabilityZonesRecord()).thenReturn(zones); when(koalaIdFactory.getRegion()).thenReturn(REGION_ZONE_1_CODE); setupDht(); rebootInstanceServiceHelper.setPiIdBuilder(piIdBuilder); }
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); }