@Test public void shouldStoreRawData() { final int typeIdOne = 333; final long keyOne = 777L; final MutableDirectBuffer keyOneBuffer = new UnsafeBuffer(ByteBuffer.allocateDirect(8)); keyOneBuffer.putLong(0, keyOne); final DirectBuffer labelOneBuffer = new UnsafeBuffer("Test Label One".getBytes(US_ASCII)); final int typeIdTwo = 222; final long keyTwo = 444; final MutableDirectBuffer keyTwoBuffer = new UnsafeBuffer(ByteBuffer.allocateDirect(8)); keyTwoBuffer.putLong(0, keyTwo); final DirectBuffer labelTwoBuffer = new UnsafeBuffer("Test Label Two".getBytes(US_ASCII)); final int counterIdOne = manager.allocate( typeIdOne, keyOneBuffer, 0, keyOneBuffer.capacity(), labelOneBuffer, 0, labelOneBuffer.capacity()); final int counterIdTwo = manager.allocate( typeIdTwo, keyTwoBuffer, 0, keyTwoBuffer.capacity(), labelTwoBuffer, 0, labelTwoBuffer.capacity()); manager.forEach(metaData); final ArgumentCaptor<DirectBuffer> argCaptorOne = ArgumentCaptor.forClass(DirectBuffer.class); final ArgumentCaptor<DirectBuffer> argCaptorTwo = ArgumentCaptor.forClass(DirectBuffer.class); final InOrder inOrder = Mockito.inOrder(metaData); inOrder.verify(metaData).accept(eq(counterIdOne), eq(typeIdOne), argCaptorOne.capture(), eq("Test Label One")); inOrder.verify(metaData).accept(eq(counterIdTwo), eq(typeIdTwo), argCaptorTwo.capture(), eq("Test Label Two")); inOrder.verifyNoMoreInteractions(); final DirectBuffer keyOneBufferCapture = argCaptorOne.getValue(); assertThat(keyOneBufferCapture.getLong(0), is(keyOne)); final DirectBuffer keyTwoBufferCapture = argCaptorTwo.getValue(); assertThat(keyTwoBufferCapture.getLong(0), is(keyTwo)); }
/** * Iterate over all the metadata in the buffer. * * @param metaData function to be called for each metadata record. */ public void forEach(final MetaData metaData) { int counterId = 0; for (int i = 0, capacity = metaDataBuffer.capacity(); i < capacity; i += METADATA_LENGTH) { final int recordStatus = metaDataBuffer.getIntVolatile(i); if (RECORD_UNUSED == recordStatus) { break; } else if (RECORD_ALLOCATED == recordStatus) { final int typeId = metaDataBuffer.getInt(i + TYPE_ID_OFFSET); final String label = metaDataBuffer.getStringUtf8(i + LABEL_OFFSET); final DirectBuffer keyBuffer = new UnsafeBuffer(metaDataBuffer, i + KEY_OFFSET, MAX_KEY_LENGTH); metaData.accept(counterId, typeId, keyBuffer, label); } counterId++; } }
/** * Iterate over all the metadata in the buffer. * * @param metaData function to be called for each metadata record. */ public void forEach(final MetaData metaData) { int counterId = 0; for (int i = 0, capacity = metaDataBuffer.capacity(); i < capacity; i += METADATA_LENGTH) { final int recordStatus = metaDataBuffer.getIntVolatile(i); if (RECORD_ALLOCATED == recordStatus) { final int typeId = metaDataBuffer.getInt(i + TYPE_ID_OFFSET); final String label = labelValue(i); final DirectBuffer keyBuffer = new UnsafeBuffer(metaDataBuffer, i + KEY_OFFSET, MAX_KEY_LENGTH); metaData.accept(counterId, typeId, keyBuffer, label); } else if (RECORD_UNUSED == recordStatus) { break; } counterId++; } }
/** * Iterate over all the metadata in the buffer. * * @param metaData function to be called for each metadata record. */ public void forEach(final MetaData metaData) { int counterId = 0; for (int i = 0, capacity = metaDataBuffer.capacity(); i < capacity; i += METADATA_LENGTH) { final int recordStatus = metaDataBuffer.getIntVolatile(i); if (RECORD_ALLOCATED == recordStatus) { final int typeId = metaDataBuffer.getInt(i + TYPE_ID_OFFSET); final String label = labelValue(i); final DirectBuffer keyBuffer = new UnsafeBuffer(metaDataBuffer, i + KEY_OFFSET, MAX_KEY_LENGTH); metaData.accept(counterId, typeId, keyBuffer, label); } else if (RECORD_UNUSED == recordStatus) { break; } counterId++; } }
@Test public void shouldStoreMetaData() { final int typeIdOne = 333; final long keyOne = 777L; final int typeIdTwo = 222; final long keyTwo = 444; final int counterIdOne = manager.allocate("Test Label One", typeIdOne, (buffer) -> buffer.putLong(0, keyOne)); final int counterIdTwo = manager.allocate("Test Label Two", typeIdTwo, (buffer) -> buffer.putLong(0, keyTwo)); manager.forEach(metaData); final ArgumentCaptor<DirectBuffer> argCaptorOne = ArgumentCaptor.forClass(DirectBuffer.class); final ArgumentCaptor<DirectBuffer> argCaptorTwo = ArgumentCaptor.forClass(DirectBuffer.class); final InOrder inOrder = Mockito.inOrder(metaData); inOrder.verify(metaData).accept(eq(counterIdOne), eq(typeIdOne), argCaptorOne.capture(), eq("Test Label One")); inOrder.verify(metaData).accept(eq(counterIdTwo), eq(typeIdTwo), argCaptorTwo.capture(), eq("Test Label Two")); inOrder.verifyNoMoreInteractions(); final DirectBuffer keyOneBuffer = argCaptorOne.getValue(); assertThat(keyOneBuffer.getLong(0), is(keyOne)); final DirectBuffer keyTwoBuffer = argCaptorTwo.getValue(); assertThat(keyTwoBuffer.getLong(0), is(keyTwo)); }