示例#1
0
  @Test
  public void testGetContentHandle() {
    // setup
    long time = System.currentTimeMillis();
    when(mockTimeSource.currentTimeMillis()).thenReturn(time);
    when(mockPast.getLocalNodeHandle()).thenReturn(mockNodeHandle);
    when(mockPast.getEnvironment()).thenReturn(mockEnvironment);

    // act
    PastContentHandle contentHandle = content.getHandle(mockPast);

    // assert
    assertNotNull(contentHandle);
    assertEquals(mockNodeHandle, contentHandle.getNodeHandle());
    assertEquals(id, contentHandle.getId());
    assertTrue(contentHandle instanceof KoalaContentHandleBase);
    assertEquals(time, ((KoalaContentHandleBase) contentHandle).getTimeStamp());
    assertEquals(
        time + (7 * 24 * 60 * 60 * 1000), ((KoalaContentHandleBase) contentHandle).getExpiration());
  }
示例#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);
  }