Example #1
0
  @Test
  public void testHandleRequestGreatThanMaxOffsetSliceNull() throws Exception {
    final int partition = 1;
    final int opaque = 0;
    final int maxSize = 1024;
    final long offset = 10;
    final MessageStore store = this.mocksControl.createMock(MessageStore.class);
    EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store);
    EasyMock.expect(store.slice(offset, maxSize)).andReturn(null);
    this.conn.response(
        new BooleanCommand(
            opaque, HttpStatus.NotFound, "Could not find message at position " + offset));
    EasyMock.expect(store.getMaxOffset()).andReturn(offset - 1);
    EasyMock.expectLastCall();
    this.mocksControl.replay();

    final GetCommand request =
        new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque);
    this.getProcessor.handleRequest(request, this.conn);
    this.mocksControl.verify();
    assertEquals(1, this.statsManager.getCmdGetMiss());
    assertEquals(1, this.statsManager.getCmdGets());
    assertEquals(0, this.statsManager.getCmdOffsets());
  }
Example #2
0
  @Test
  public void testHandleRequestMaxOffset() throws Exception {
    // 从实际最大的offset开始订阅
    final int partition = 1;
    final int opaque = 0;
    final int maxSize = 1024;
    final long offset = Long.MAX_VALUE;
    final long realMaxOffset = 100;
    final MessageStore store = this.mocksControl.createMock(MessageStore.class);
    EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store);
    EasyMock.expect(store.slice(offset, maxSize)).andReturn(null);
    this.conn.response(new BooleanCommand(opaque, HttpStatus.Moved, String.valueOf(realMaxOffset)));
    EasyMock.expect(store.getMaxOffset()).andReturn(realMaxOffset);
    EasyMock.expectLastCall();
    this.mocksControl.replay();

    final GetCommand request =
        new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque);
    this.getProcessor.handleRequest(request, this.conn);
    this.mocksControl.verify();
    assertEquals(1, this.statsManager.getCmdGetMiss());
    assertEquals(1, this.statsManager.getCmdGets());
    assertEquals(1, this.statsManager.getCmdOffsets());
  }