Пример #1
0
  /** When BACKUP_PACKET is received, updates are written to store */
  @Test
  public void whenBACKUP_PACKETThenWriteUpdates() throws Exception {
    final ByteBuffer buffer1 = randomBuffer(50);
    final ByteBuffer buffer2 = randomBuffer(50);
    final ByteBuffer buffer3 = randomBuffer(50);

    final BACKUP_PACKET bp =
        Message.BACKUP_PACKET(
            7,
            Arrays.asList(
                Message.BACKUP(id(1), 4, buffer1),
                Message.BACKUP(id(2), 5, buffer2),
                Message.BACKUP(id(3), 6, buffer3)));
    bp.setNode(sh(10));
    mm.receive(bp);

    InOrder inOrder = inOrder(store, comm);
    inOrder.verify(store).beginTransaction();
    inOrder
        .verify(store)
        .write(eq(id(1)), eq(sh(10)), eq(4L), eq(Persistables.toByteArray(buffer1)), anyObject());
    inOrder
        .verify(store)
        .write(eq(id(2)), eq(sh(10)), eq(5L), eq(Persistables.toByteArray(buffer2)), anyObject());
    inOrder
        .verify(store)
        .write(eq(id(3)), eq(sh(10)), eq(6L), eq(Persistables.toByteArray(buffer3)), anyObject());
    inOrder.verify(store).commit(anyObject());
    inOrder.verify(comm).send(argThat(equalTo(Message.BACKUP_PACKETACK(bp))));
    verify(monitor).addTransaction(3);
    verifyNoMoreInteractions(monitor);
  }
Пример #2
0
  /** When INV is received but previous owner is wrong, don't change the owner and reply INV. */
  @Test
  public void whenINVAndWrongPreviousOwnerThenINV() throws Exception {
    when(store.casOwner(id(154), sh(5), sh(10))).thenReturn(sh(20));
    final Message.INV inv = Message.INV(sh(10), id(154), sh(5));
    mm.receive(inv);

    verify(store).casOwner(id(154), sh(5), sh(10));
    verify(comm).send(argThat(equalTo(Message.INV(inv, id(154), sh(20)))));
    verify(monitor).addOwnerServed();
    verifyNoMoreInteractions(monitor);
  }
Пример #3
0
  /**
   * When INV is received, the owner is registered in the store as the owner of the line, and reply
   * INVACK.
   */
  @Test
  public void whenINVThenMarkOwnerAndINVACK() throws Exception {
    when(store.casOwner(id(154), sh(5), sh(10))).thenReturn(sh(10));
    final Message.INV inv = Message.INV(sh(10), id(154), sh(5));
    mm.receive(inv);

    verify(store).casOwner(id(154), sh(5), sh(10));
    verify(comm).send(argThat(equalTo(Message.INVACK(inv))));
    verify(monitor).addOwnerWrite();
    verifyNoMoreInteractions(monitor);
  }
Пример #4
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);
  }
Пример #5
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);
  }
Пример #6
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);
  }