Exemplo n.º 1
0
  @Test
  public void shouldNotStoreLocallyWhenReplicationFetchingIfNullType() throws Exception {
    // setup
    KoalaPastPolicy koalaPastPolicy = mock(KoalaPastPolicy.class);
    koalaGCPastImpl =
        new KoalaGCPastImpl(
            node,
            storageManager,
            null,
            0,
            instance,
            koalaPastPolicy,
            0,
            storageManager,
            KoalaNode.DEFAULT_NUMBER_OF_DHT_BACKUPS,
            koalaIdFactory,
            koalaPiEntityFactory);

    Id id = mock(Id.class);
    GCId gcId = mock(GCId.class);
    when(gcId.getId()).thenReturn(id);
    when(storageManager.exists(id)).thenReturn(false);
    NodeHandle hint = mock(NodeHandle.class);
    final CountDownLatch latch = new CountDownLatch(1);

    doAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                StandardContinuation continuation =
                    (StandardContinuation) invocation.getArguments()[4];
                continuation.receiveResult(content);
                latch.countDown();
                return null;
              }
            })
        .when(koalaPastPolicy)
        .fetch(
            eq(id), eq(hint), (Cache) isNull(), isA(Past.class), isA(StandardContinuation.class));

    Storage storage = mock(Storage.class);
    when(storageManager.getStorage()).thenReturn(storage);

    String json = "what";
    content = new KoalaPiEntityContent(messageId, json, false, null, 1, NodeScope.GLOBAL, "", 0);

    // act
    koalaGCPastImpl.fetch(gcId, hint, mock(Continuation.class));

    // assert
    assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
    verify(storage, never())
        .store(eq(id), isA(GCPastMetadata.class), eq(content), isA(Continuation.class));
  }
Exemplo n.º 2
0
 @Test(expected = IllegalArgumentException.class)
 public void testFetchNotGCId() {
   // act
   koalaGCPastImpl.fetch(mock(Id.class), mock(NodeHandle.class), mock(Continuation.class));
 }