Ejemplo n.º 1
0
  @Test
  public void shouldNotUnmapBuffersBeforeLastRelease() throws Exception {
    publication.incRef();
    publication.close();

    verify(logBuffers, never()).close();
  }
Ejemplo n.º 2
0
  @Test
  public void shouldUnmapBuffersWithMultipleReferences() throws Exception {
    publication.incRef();
    publication.close();

    publication.close();
    logBuffersClosedOnce();
  }
Ejemplo n.º 3
0
  @Test
  public void shouldEnsureThePublicationIsOpenBeforeReadingPosition() {
    publication.close();
    assertThat(publication.position(), is(Publication.CLOSED));

    final InOrder inOrder = Mockito.inOrder(conductorLock, conductor);
    inOrder.verify(conductorLock).lock();
    inOrder.verify(conductor).releasePublication(publication);
    inOrder.verify(conductorLock).unlock();
  }
Ejemplo n.º 4
0
  @Test
  public void shouldNotUnmapBuffersBeforeLastRelease() throws Exception {
    publication.incRef();
    publication.close();

    verify(logBuffers, never()).close();

    final InOrder inOrder = Mockito.inOrder(conductorLock, conductor);
    inOrder.verify(conductorLock).lock();
    inOrder.verify(conductorLock).unlock();
    inOrder.verifyNoMoreInteractions();
  }
Ejemplo n.º 5
0
  @Test
  public void shouldUnmapBuffersWithMultipleReferences() throws Exception {
    publication.incRef();
    publication.close();

    publication.close();

    final InOrder inOrder = Mockito.inOrder(conductorLock, conductor);
    inOrder.verify(conductorLock).lock();
    inOrder.verify(conductor).releasePublication(publication);
    inOrder.verify(conductorLock).unlock();
    inOrder.verifyNoMoreInteractions();
  }
Ejemplo n.º 6
0
  @Before
  public void setUp() {
    when(publicationLimit.getVolatile()).thenReturn(2L * SEND_BUFFER_CAPACITY);
    when(logBuffers.termBuffers()).thenReturn(termBuffers);
    when(logBuffers.termLength()).thenReturn(TERM_MIN_LENGTH);
    when(logBuffers.metaDataBuffer()).thenReturn(logMetaDataBuffer);
    when(conductor.mainLock()).thenReturn(conductorLock);

    initialTermId(logMetaDataBuffer, TERM_ID_1);
    timeOfLastStatusMessage(logMetaDataBuffer, 0);

    for (int i = 0; i < PARTITION_COUNT; i++) {
      termBuffers[i] = new UnsafeBuffer(allocateDirect(TERM_MIN_LENGTH));
    }

    publication =
        new Publication(
            conductor,
            CHANNEL,
            STREAM_ID_1,
            SESSION_ID_1,
            publicationLimit,
            logBuffers,
            CORRELATION_ID);

    publication.incRef();

    initialiseTailWithTermId(logMetaDataBuffer, PARTITION_INDEX, TERM_ID_1);
  }
Ejemplo n.º 7
0
  @Before
  public void setUp() {
    when(publicationLimit.getVolatile()).thenReturn(2L * SEND_BUFFER_CAPACITY);
    when(logBuffers.atomicBuffers()).thenReturn(buffers);
    when(logBuffers.termLength()).thenReturn(TERM_MIN_LENGTH);

    initialTermId(logMetaDataBuffer, TERM_ID_1);
    activeTermId(logMetaDataBuffer, TERM_ID_1);

    for (int i = 0; i < PARTITION_COUNT; i++) {
      termBuffers[i] = new UnsafeBuffer(ByteBuffer.allocateDirect(TERM_MIN_LENGTH));
      termMetaDataBuffers[i] = new UnsafeBuffer(ByteBuffer.allocateDirect(TERM_META_DATA_LENGTH));

      buffers[i] = termBuffers[i];
      buffers[i + PARTITION_COUNT] = termMetaDataBuffers[i];
    }
    buffers[LOG_META_DATA_SECTION_INDEX] = logMetaDataBuffer;

    publication =
        new Publication(
            conductor,
            CHANNEL,
            STREAM_ID_1,
            SESSION_ID_1,
            publicationLimit,
            logBuffers,
            CORRELATION_ID);

    publication.incRef();
  }
Ejemplo n.º 8
0
  @Test
  public void shouldUnmapBuffersWhenReleased() throws Exception {
    publication.close();

    logBuffersClosedOnce();
    releaseSelfOnce();
  }
Ejemplo n.º 9
0
  @Test
  public void shouldReleaseResourcesIdempotently() throws Exception {
    publication.close();
    publication.close();

    logBuffersClosedOnce();
    releaseSelfOnce();
  }
Ejemplo n.º 10
0
  @Test
  public void shouldReleaseResourcesIdempotently() throws Exception {
    publication.close();
    publication.close();

    final InOrder inOrder = Mockito.inOrder(conductorLock, conductor);
    inOrder.verify(conductorLock).lock();
    inOrder.verify(conductor).releasePublication(publication);
    inOrder.verify(conductorLock).unlock();
    inOrder.verify(conductorLock).lock();
    inOrder.verify(conductorLock).unlock();
    inOrder.verifyNoMoreInteractions();
  }
Ejemplo n.º 11
0
 @Test
 public void shouldEnsureThePublicationIsOpenBeforeReadingPosition() {
   publication.close();
   assertThat(publication.position(), is(Publication.CLOSED));
 }
Ejemplo n.º 12
0
 @Test
 public void shouldEnsureThePublicationIsOpenBeforeOffer() {
   publication.close();
   assertTrue(publication.isClosed());
   assertThat(publication.offer(atomicSendBuffer), is(Publication.CLOSED));
 }
Ejemplo n.º 13
0
 @Test
 public void shouldReportThatPublicationHasBeenConnectedYet() {
   assertTrue(publication.hasBeenConnected());
 }
Ejemplo n.º 14
0
 @Test
 public void shouldReportMaxMessageLength() {
   assertThat(
       publication.maxMessageLength(),
       is(FrameDescriptor.computeMaxMessageLength(TERM_MIN_LENGTH)));
 }
Ejemplo n.º 15
0
 @Test
 public void shouldReportInitialPosition() {
   assertThat(publication.position(), is(0L));
 }
Ejemplo n.º 16
0
 @Test
 public void shouldReportThatPublicationHasBeenConnectedYet() {
   when(conductor.isPublicationConnected(anyLong())).thenReturn(true);
   assertTrue(publication.isConnected());
 }
Ejemplo n.º 17
0
 @Test
 public void shouldReportThatPublicationHasNotBeenConnectedYet() {
   when(publicationLimit.getVolatile()).thenReturn(0L);
   when(conductor.isPublicationConnected(anyLong())).thenReturn(false);
   assertFalse(publication.isConnected());
 }
Ejemplo n.º 18
0
 @Test
 public void shouldEnsureThePublicationIsOpenBeforeClaim() {
   publication.close();
   final BufferClaim bufferClaim = new BufferClaim();
   assertThat(publication.tryClaim(SEND_BUFFER_CAPACITY, bufferClaim), is(Publication.CLOSED));
 }
Ejemplo n.º 19
0
 @Test
 public void shouldReportThatPublicationHasNotBeenConnectedYet() {
   when(publicationLimit.getVolatile()).thenReturn(0L);
   assertFalse(publication.hasBeenConnected());
 }