예제 #1
0
  /** When GET is received and owner is not found, reply with NOT_FOUND */
  @Test
  public void whenGETAndNoOwnerThenReplyNOT_FOUND() throws Exception {
    when(store.casOwner(id(154), sh(0), sh(10))).thenReturn(sh(-1));
    when(store.findAllocation(id(154))).thenReturn(sh(-1));

    final LineMessage get = Message.GET(sh(10), id(154));
    mm.receive(get);

    verify(comm).send(argThat(equalTo(Message.NOT_FOUND(get))));
  }
예제 #2
0
  /** When GET is received and owner is a node other than server, reply with a CHNGD_OWNR */
  @Test
  public void whenGETAndHasOwnerThenReplyCHNGD_OWNR() throws Exception {
    when(store.casOwner(id(154), sh(0), sh(10))).thenReturn(sh(3));

    final LineMessage get = Message.GET(sh(10), id(154));
    mm.receive(get);

    verify(comm).send(argThat(equalTo(Message.CHNGD_OWNR(get, id(154), sh(3), true))));
    verify(monitor).addOwnerServed();
    verifyNoMoreInteractions(monitor);
  }
예제 #3
0
  /**
   * When GET is received and owner is not found but line is reserved, then create line and reply
   * with PUTX
   */
  @Test
  public void whenGETReservedAndNoOwnerThenCreateAndReplyPUTX() throws Exception {
    when(store.casOwner(15, sh(-1), sh(10))).thenReturn(sh(10));

    final LineMessage get = Message.GET(sh(10), 15);
    mm.receive(get);

    verify(store).casOwner(15, sh(-1), sh(10));
    verify(store).write(15, sh(10), 1, new byte[0], null);
    verify(comm).send(argThat(equalTo(Message.PUTX(get, 15, new short[0], 0, 1, null))));
    verify(monitor).addObjectServed();
    verify(monitor).addOwnerWrite();
    verifyNoMoreInteractions(monitor);
  }
예제 #4
0
  /** When GET is received and server is owner then reply with PUTX */
  @Test
  public void whenGETAndServerIsOwnerThenReplyPUTX() throws Exception {
    when(store.casOwner(id(154), sh(0), sh(10))).thenReturn(sh(10));
    when(store.read(id(154))).thenReturn(new MainMemoryEntry(1234, new byte[] {3, 4, 5}));
    final LineMessage get = Message.GET(sh(10), id(154));
    mm.receive(get);

    verify(store).casOwner(id(154), sh(0), sh(10));
    verify(store).read(id(154));
    verify(comm)
        .send(
            argThat(
                equalTo(
                    Message.PUTX(
                        get,
                        id(154),
                        new short[0],
                        0,
                        1234,
                        ByteBuffer.wrap(new byte[] {3, 4, 5})))));
    verify(monitor).addObjectServed();
    verify(monitor).addOwnerWrite();
    verifyNoMoreInteractions(monitor);
  }