@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final RingBuffer fromClientCommands = new ManyToOneRingBuffer( new UnsafeBuffer(ByteBuffer.allocateDirect(Configuration.CONDUCTOR_BUFFER_LENGTH))); final RawLogFactory mockRawLogFactory = mock(RawLogFactory.class); final UnsafeBuffer counterBuffer = new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_LENGTH)); final CountersManager countersManager = new CountersManager( new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_LENGTH)), counterBuffer); when(mockRawLogFactory.newDirectPublication(anyInt(), anyInt(), anyLong())) .thenReturn(LogBufferHelper.newTestLogBuffers(TERM_BUFFER_LENGTH, TERM_META_DATA_LENGTH)); final MediaDriver.Context ctx = new MediaDriver.Context() .toDriverCommands(fromClientCommands) .rawLogBuffersFactory(mockRawLogFactory) .clientProxy(mock(ClientProxy.class)) .eventLogger(mock(EventLogger.class)) .toConductorFromReceiverCommandQueue(mock(OneToOneConcurrentArrayQueue.class)) .toConductorFromSenderCommandQueue(mock(OneToOneConcurrentArrayQueue.class)) .toEventReader(mock(ManyToOneRingBuffer.class)) .epochClock(new SystemEpochClock()) .countersManager(countersManager) .nanoClock(nanoClock); ctx.counterValuesBuffer(counterBuffer); driverProxy = new DriverProxy(fromClientCommands); driverConductor = new DriverConductor(ctx); // have a conductor construct one for us driverProxy.addPublication(CommonContext.IPC_CHANNEL, STREAM_ID); driverConductor.doWork(); directPublication = driverConductor.getDirectPublication(STREAM_ID); publisherLimit = new UnsafeBufferPosition(counterBuffer, directPublication.publisherLimitId()); }