Ejemplo n.º 1
0
  @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));
  }
Ejemplo n.º 2
0
  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);
  }