Exemplo n.º 1
0
  @Test
  public void testDoInsertCheckInsertFails() {
    // setup
    Continuation continuation = mock(Continuation.class);

    doAnswer(
            new Answer<Object>() {
              public Object answer(InvocationOnMock invocation) throws Throwable {
                // KoalaMutableContent existingContent = new KoalaPiEntityContent(dhtId, "what2",
                // new HashMap<String,
                // String>());
                KoalaMutableContent existingContent =
                    new KoalaPiEntityContent(messageId, "what2", new HashMap<String, String>());
                existingContent
                    .getContentHeaders()
                    .put(DhtContentHeader.CONTENT_VERSION, Long.toString(2));
                ((StandardContinuation) invocation.getArguments()[1])
                    .receiveResult(existingContent);
                return null;
              }
            })
        .when(storageManager)
        .getObject(eq(messageId), isA(StandardContinuation.class));

    // act
    koalaGCPastImpl.doInsert(content.getId(), builder, continuation, false);

    // verify
    verify(continuation).receiveException(isA(PastException.class));
  }
Exemplo n.º 2
0
  @Test
  public void testDoInsert() {
    final Object expectedResult = new Object();
    Continuation continuation = mock(Continuation.class);
    doAnswer(
            new Answer<Object>() {
              public Object answer(InvocationOnMock invocation) throws Throwable {
                // KoalaMutableContent existingContent = new KoalaPiEntityContent(dhtId, "what2",
                // new HashMap<String,
                // String>());
                KoalaMutableContent existingContent =
                    new KoalaPiEntityContent(messageId, "what2", new HashMap<String, String>());
                ((StandardContinuation) invocation.getArguments()[1])
                    .receiveResult(existingContent);
                return null;
              }
            })
        .when(storageManager)
        .getObject(eq(messageId), isA(StandardContinuation.class));

    doAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                ((StandardContinuation) invocation.getArguments()[3]).receiveResult(expectedResult);
                return null;
              }
            })
        .when(storageManager)
        .store(
            eq(messageId),
            (Serializable)
                argThat(
                    new ArgumentMatcher<GCPastMetadata>() {
                      @Override
                      public boolean matches(Object argument) {
                        if (!(argument instanceof GCPastMetadata)) return false;
                        GCPastMetadata koalaContentMetadata = (GCPastMetadata) argument;
                        return koalaContentMetadata.getExpiration() == content.getVersion();
                      }
                    }),
            argThat(
                new ArgumentMatcher<KoalaMutableContent>() {
                  @Override
                  public boolean matches(Object argument) {
                    if (!(argument instanceof KoalaMutableContent)) return false;
                    KoalaMutableContent koalaMutableContent = (KoalaMutableContent) argument;
                    rice.p2p.commonapi.Id id = koalaMutableContent.getId();
                    return id.equals(messageId);
                    // return id.toStringFull().endsWith("0001");
                  }
                }),
            isA(StandardContinuation.class));

    // act
    koalaGCPastImpl.doInsert(content.getId(), builder, continuation, false);

    // verify
    assertEquals(messageId, getHandlesId);
    assertTrue(getHandlesContinuation instanceof KoalaPastGetHandlesInsertContinuation);
  }