public void AddSubscriptionShouldNotifyMediaDriver() { WhenReceiveBroadcastOnMessage(ControlProtocolEvents.ON_OPERATION_SUCCESS, CorrelatedMessageBuffer, (buffer) => { CorrelatedMessage.CorrelationId(CORRELATION_ID); return(CorrelatedMessageFlyweight.LENGTH); }); Conductor.AddSubscription(CHANNEL, STREAM_ID_1); A.CallTo(() => DriverProxy.AddSubscription(CHANNEL, STREAM_ID_1)).MustHaveHappened(); }
public void AddSubscriptionShouldNotifyMediaDriver() { WhenReceiveBroadcastOnMessage(ControlProtocolEvents.ON_SUBSCRIPTION_READY, SubscriptionReadyBuffer, buffer => { SubscriptionReady.CorrelationId(CORRELATION_ID); return(SubscriptionReadyFlyweight.LENGTH); }); Conductor.AddSubscription(CHANNEL, STREAM_ID_1); A.CallTo(() => DriverProxy.AddSubscription(CHANNEL, STREAM_ID_1)).MustHaveHappened(); }
public void SetUp() { MockClientErrorHandler = A.Fake <ErrorHandler>(options => options.Wrapping(throwable => { if (!SuppressPrintError) { Console.WriteLine(throwable.ToString()); Console.Write(throwable.StackTrace); } })); PublicationReady = new PublicationBuffersReadyFlyweight(); CorrelatedMessage = new CorrelatedMessageFlyweight(); ErrorResponse = new ErrorResponseFlyweight(); PublicationReadyBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); CorrelatedMessageBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); ErrorMessageBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); CounterValuesBuffer = new UnsafeBuffer(new byte[COUNTER_BUFFER_LENGTH]); MockToClientReceiver = A.Fake <CopyBroadcastReceiver>(); MockAvailableImageHandler = A.Fake <AvailableImageHandler>(); MockUnavailableImageHandler = A.Fake <UnavailableImageHandler>(); LogBuffersFactory = A.Fake <ILogBuffersFactory>(); SubscriberPositionMap = new Dictionary <long, long>(); // should return -1 when element does not exist DriverProxy = A.Fake <DriverProxy>(); A.CallTo(() => DriverProxy.AddPublication(CHANNEL, STREAM_ID_1)).Returns(CORRELATION_ID); A.CallTo(() => DriverProxy.AddPublication(CHANNEL, STREAM_ID_2)).Returns(CORRELATION_ID_2); A.CallTo(() => DriverProxy.RemovePublication(CORRELATION_ID)).Returns(CLOSE_CORRELATION_ID); A.CallTo(() => DriverProxy.AddSubscription(A <string> ._, A <int> ._)).Returns(CORRELATION_ID); A.CallTo(() => DriverProxy.RemoveSubscription(CORRELATION_ID)).Returns(CLOSE_CORRELATION_ID); Conductor = new ClientConductor(EpochClock, NanoClock, MockToClientReceiver, LogBuffersFactory, CounterValuesBuffer, DriverProxy, MockClientErrorHandler, MockAvailableImageHandler, MockUnavailableImageHandler, MapMode.ReadOnly, KEEP_ALIVE_INTERVAL, AWAIT_TIMEOUT, NanoUtil.FromMilliseconds(INTER_SERVICE_TIMEOUT_MS), PUBLICATION_CONNECTION_TIMEOUT_MS); PublicationReady.Wrap(PublicationReadyBuffer, 0); CorrelatedMessage.Wrap(CorrelatedMessageBuffer, 0); ErrorResponse.Wrap(ErrorMessageBuffer, 0); PublicationReady.CorrelationId(CORRELATION_ID); PublicationReady.SessionId(SESSION_ID_1); PublicationReady.StreamId(STREAM_ID_1); PublicationReady.LogFileName(SESSION_ID_1 + "-log"); SubscriberPositionMap.Add(CORRELATION_ID, 0); CorrelatedMessage.CorrelationId(CLOSE_CORRELATION_ID); var termBuffersSession1 = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; var termBuffersSession2 = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { termBuffersSession1[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); termBuffersSession2[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); } UnsafeBuffer logMetaDataSession1 = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); UnsafeBuffer logMetaDataSession2 = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); IMutableDirectBuffer header1 = DataHeaderFlyweight.CreateDefaultHeader(SESSION_ID_1, STREAM_ID_1, 0); IMutableDirectBuffer header2 = DataHeaderFlyweight.CreateDefaultHeader(SESSION_ID_2, STREAM_ID_2, 0); LogBufferDescriptor.StoreDefaultFrameHeader(logMetaDataSession1, header1); LogBufferDescriptor.StoreDefaultFrameHeader(logMetaDataSession2, header2); var logBuffersSession1 = A.Fake <LogBuffers>(); var logBuffersSession2 = A.Fake <LogBuffers>(); A.CallTo(() => LogBuffersFactory.Map(SESSION_ID_1 + "-log", A <MapMode> ._)).Returns(logBuffersSession1); A.CallTo(() => LogBuffersFactory.Map(SESSION_ID_2 + "-log", A <MapMode> ._)).Returns(logBuffersSession2); A.CallTo(() => logBuffersSession1.TermBuffers()).Returns(termBuffersSession1); A.CallTo(() => logBuffersSession2.TermBuffers()).Returns(termBuffersSession2); A.CallTo(() => logBuffersSession1.MetaDataBuffer()).Returns(logMetaDataSession1); A.CallTo(() => logBuffersSession2.MetaDataBuffer()).Returns(logMetaDataSession2); }
public void SetUp() { MockClientErrorHandler = A.Fake <ErrorHandler>(options => options.Wrapping(throwable => { if (!SuppressPrintError) { Console.WriteLine(throwable.ToString()); Console.Write(throwable.StackTrace); } })); PublicationReady = new PublicationBuffersReadyFlyweight(); SubscriptionReady = new SubscriptionReadyFlyweight(); OperationSuccess = new OperationSucceededFlyweight(); ErrorResponse = new ErrorResponseFlyweight(); ClientTimeout = new ClientTimeoutFlyweight(); PublicationReadyBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); SubscriptionReadyBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); OperationSuccessBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); ErrorMessageBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); ClientTimeoutBuffer = new UnsafeBuffer(new byte[SEND_BUFFER_CAPACITY]); CounterValuesBuffer = new UnsafeBuffer(new byte[COUNTER_BUFFER_LENGTH]); MockToClientReceiver = A.Fake <CopyBroadcastReceiver>(); MockAvailableImageHandler = A.Fake <AvailableImageHandler>(); MockUnavailableImageHandler = A.Fake <UnavailableImageHandler>(); MockCloseHandler = A.Fake <Action>(); LogBuffersFactory = A.Fake <ILogBuffersFactory>(); DriverProxy = A.Fake <DriverProxy>(); MockAeron = A.Fake <Aeron>(); A.CallTo(() => mockClientLock.TryLock()).Returns(true); A.CallTo(() => DriverProxy.AddPublication(CHANNEL, STREAM_ID_1)).Returns(CORRELATION_ID); A.CallTo(() => DriverProxy.AddPublication(CHANNEL, STREAM_ID_2)).Returns(CORRELATION_ID_2); A.CallTo(() => DriverProxy.RemovePublication(CORRELATION_ID)).Returns(CLOSE_CORRELATION_ID); A.CallTo(() => DriverProxy.AddSubscription(A <string> ._, A <int> ._)).Returns(CORRELATION_ID); A.CallTo(() => DriverProxy.RemoveSubscription(CORRELATION_ID)).Returns(CLOSE_CORRELATION_ID); Aeron.Context ctx = new Aeron.Context() .ClientLock(mockClientLock) .EpochClock(EpochClock) .NanoClock(NanoClock) .ToClientBuffer(MockToClientReceiver) .DriverProxy(DriverProxy) .LogBuffersFactory(LogBuffersFactory) .ErrorHandler(MockClientErrorHandler) .AvailableImageHandler(MockAvailableImageHandler) .UnavailableImageHandler(MockUnavailableImageHandler) .CloseHandler(MockCloseHandler) .KeepAliveIntervalNs(KEEP_ALIVE_INTERVAL) .DriverTimeoutMs(AWAIT_TIMEOUT) .InterServiceTimeoutNs(INTER_SERVICE_TIMEOUT_MS * 1000000) .CountersValuesBuffer(CounterValuesBuffer); Conductor = new ClientConductor(ctx, MockAeron); PublicationReady.Wrap(PublicationReadyBuffer, 0); SubscriptionReady.Wrap(SubscriptionReadyBuffer, 0); OperationSuccess.Wrap(OperationSuccessBuffer, 0); ErrorResponse.Wrap(ErrorMessageBuffer, 0); ClientTimeout.Wrap(ClientTimeoutBuffer, 0); PublicationReady.CorrelationId(CORRELATION_ID); PublicationReady.RegistrationId(CORRELATION_ID); PublicationReady.SessionId(SESSION_ID_1); PublicationReady.StreamId(STREAM_ID_1); PublicationReady.LogFileName(SESSION_ID_1 + "-log"); OperationSuccess.CorrelationId(CLOSE_CORRELATION_ID); var termBuffersSession1 = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; var termBuffersSession2 = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { termBuffersSession1[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); termBuffersSession2[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); } UnsafeBuffer logMetaDataSession1 = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); UnsafeBuffer logMetaDataSession2 = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); IMutableDirectBuffer header1 = DataHeaderFlyweight.CreateDefaultHeader(SESSION_ID_1, STREAM_ID_1, 0); IMutableDirectBuffer header2 = DataHeaderFlyweight.CreateDefaultHeader(SESSION_ID_2, STREAM_ID_2, 0); LogBufferDescriptor.StoreDefaultFrameHeader(logMetaDataSession1, header1); LogBufferDescriptor.StoreDefaultFrameHeader(logMetaDataSession2, header2); var logBuffersSession1 = A.Fake <LogBuffers>(); var logBuffersSession2 = A.Fake <LogBuffers>(); A.CallTo(() => LogBuffersFactory.Map(SESSION_ID_1 + "-log")).Returns(logBuffersSession1); A.CallTo(() => LogBuffersFactory.Map(SESSION_ID_2 + "-log")).Returns(logBuffersSession2); A.CallTo(() => logBuffersSession1.DuplicateTermBuffers()).Returns(termBuffersSession1); A.CallTo(() => logBuffersSession2.DuplicateTermBuffers()).Returns(termBuffersSession2); A.CallTo(() => logBuffersSession1.MetaDataBuffer()).Returns(logMetaDataSession1); A.CallTo(() => logBuffersSession2.MetaDataBuffer()).Returns(logMetaDataSession2); A.CallTo(() => logBuffersSession1.TermLength()).Returns(TERM_BUFFER_LENGTH); A.CallTo(() => logBuffersSession2.TermLength()).Returns(TERM_BUFFER_LENGTH); }