本文整理汇总了C#中BrokerRouterProxy类的典型用法代码示例。如果您正苦于以下问题:C# BrokerRouterProxy类的具体用法?C# BrokerRouterProxy怎么用?C# BrokerRouterProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BrokerRouterProxy类属于命名空间,在下文中一共展示了BrokerRouterProxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CancellationShouldInterruptConsumption
public void CancellationShouldInterruptConsumption()
{
var routerProxy = new BrokerRouterProxy(new MoqMockingKernel());
routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };
var router = routerProxy.Create();
var options = CreateOptions(router);
using (var consumer = new Consumer(options))
{
var tokenSrc = new CancellationTokenSource();
var consumeTask = Task.Run(() => consumer.Consume(tokenSrc.Token).FirstOrDefault());
//wait until the fake broker is running and requesting fetches
TaskTest.WaitFor(() => routerProxy.BrokerConn0.FetchRequestCallCount > 10);
tokenSrc.Cancel();
Assert.That(
Assert.Throws<AggregateException>(consumeTask.Wait).InnerException,
Is.TypeOf<OperationCanceledException>());
}
}
示例2: ShouldTryToRefreshMataDataIfCanRecoverByRefreshMetadata
public async Task ShouldTryToRefreshMataDataIfCanRecoverByRefreshMetadata(ErrorResponseCode code)
{
var routerProxy = new BrokerRouterProxy(_kernel);
routerProxy._cacheExpiration = new TimeSpan(10);
var router = routerProxy.Create();
int partitionId = 0;
ProtocolGateway protocolGateway = new ProtocolGateway(router);
var fetchRequest = new FetchRequest();
bool sendExOnFirstTime = true;
Func<Task<FetchResponse>> ShouldReturnErrorAndThenNoError = async () =>
{
Task.Delay(routerProxy._cacheExpiration).Wait();
Task.Delay(1).Wait();
if (sendExOnFirstTime)
{
sendExOnFirstTime = false;
return new FetchResponse() { Error = (short)code };
}
return new FetchResponse() { Error = (short)ErrorResponseCode.NoError };
};
routerProxy.BrokerConn0.FetchResponseFunction = ShouldReturnErrorAndThenNoError;
routerProxy.BrokerConn0.MetadataResponseFunction = BrokerRouterProxy.DefaultMetadataResponse;
await protocolGateway.SendProtocolRequest(fetchRequest, BrokerRouterProxy.TestTopic, partitionId);
Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(2));
Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.EqualTo(2));
}
示例3: EmptyTopicMetadataShouldThrowException
public void EmptyTopicMetadataShouldThrowException()
{
var routerProxy = new BrokerRouterProxy(_kernel);
var router = routerProxy.Create();
var common = new CommonQueries(router);
common.GetTopic("MissingTopic");
}
示例4: ShouldThrowFormatExceptionWhenTopicIsInvalid
public async Task ShouldThrowFormatExceptionWhenTopicIsInvalid()
{
var routerProxy = new BrokerRouterProxy(_kernel);
var router = routerProxy.Create();
string invalidTopic = " ";
var fetchRequest = new FetchRequest();
ProtocolGateway protocolGateway = new ProtocolGateway(router);
await protocolGateway.SendProtocolRequest(fetchRequest, invalidTopic, 0);
}
示例5: GetTopicShouldReturnTopic
public void GetTopicShouldReturnTopic()
{
var routerProxy = new BrokerRouterProxy(_kernel);
var router = routerProxy.Create();
var common = new CommonQueries(router);
var result = common.GetTopic(BrokerRouterProxy.TestTopic);
Assert.That(result.Name, Is.EqualTo(BrokerRouterProxy.TestTopic));
}
示例6: GetTopicOffsetShouldQueryEachBroker
public void GetTopicOffsetShouldQueryEachBroker()
{
var routerProxy = new BrokerRouterProxy(_kernel);
var router = routerProxy.Create();
var common = new CommonQueries(router);
var result = common.GetTopicOffsetAsync(BrokerRouterProxy.TestTopic).Result;
Assert.That(routerProxy.BrokerConn0.OffsetRequestCallCount, Is.EqualTo(1));
Assert.That(routerProxy.BrokerConn1.OffsetRequestCallCount, Is.EqualTo(1));
}
示例7: BrokerRouteShouldCycleThroughEachBrokerUntilOneIsFound
public void BrokerRouteShouldCycleThroughEachBrokerUntilOneIsFound()
{
var routerProxy = new BrokerRouterProxy(_kernel);
routerProxy.BrokerConn0.MetadataResponseFunction = () => { throw new Exception("some error"); };
var router = routerProxy.Create();
var result = router.GetTopicMetadata(TestTopic);
Assert.That(result, Is.Not.Null);
Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(1));
Assert.That(routerProxy.BrokerConn1.MetadataRequestCallCount, Is.EqualTo(1));
}
示例8: GetTopicOffsetShouldThrowAnyException
public void GetTopicOffsetShouldThrowAnyException()
{
var routerProxy = new BrokerRouterProxy(_kernel);
routerProxy.BrokerConn0.OffsetResponseFunction = () => { throw new ApplicationException("test 99"); };
var router = routerProxy.Create();
var common = new CommonQueries(router);
common.GetTopicOffsetAsync(BrokerRouterProxy.TestTopic).ContinueWith(t =>
{
Assert.That(t.IsFaulted, Is.True);
Assert.That(t.Exception.Flatten().ToString(), Is.StringContaining("test 99"));
}).Wait();
}
示例9: BrokerRouteShouldReturnTopicFromCache
public void BrokerRouteShouldReturnTopicFromCache()
{
var routerProxy = new BrokerRouterProxy(_kernel);
var router = routerProxy.Create();
var result1 = router.GetTopicMetadata(TestTopic);
var result2 = router.GetTopicMetadata(TestTopic);
Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(1));
Assert.That(result1.Count, Is.EqualTo(1));
Assert.That(result1[0].Name, Is.EqualTo(TestTopic));
Assert.That(result2.Count, Is.EqualTo(1));
Assert.That(result2[0].Name, Is.EqualTo(TestTopic));
}
示例10: ShouldTryToRefreshMataDataIfCanRecoverByRefreshMetadata
public async Task ShouldTryToRefreshMataDataIfCanRecoverByRefreshMetadata(ErrorResponseCode code)
{
var routerProxy = new BrokerRouterProxy(_kernel);
routerProxy._cacheExpiration = new TimeSpan(10);
var router = routerProxy.Create();
ProtocolGateway protocolGateway = new ProtocolGateway(router);
routerProxy.BrokerConn0.FetchResponseFunction = FailedInFirstMessageError(code, routerProxy._cacheExpiration);
routerProxy.BrokerConn0.MetadataResponseFunction = BrokerRouterProxy.CreateMetadataResponseWithMultipleBrokers;
await protocolGateway.SendProtocolRequest(new FetchRequest(), BrokerRouterProxy.TestTopic, _partitionId);
Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(2));
Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.EqualTo(2));
}
示例11: ShouldTryToRefreshMataDataIfOnExceptions
public async Task ShouldTryToRefreshMataDataIfOnExceptions(Type exceptionType)
{
var routerProxy = new BrokerRouterProxy(_kernel);
routerProxy._cacheExpiration = TimeSpan.FromMilliseconds(10);
var router = routerProxy.Create();
ProtocolGateway protocolGateway = new ProtocolGateway(router);
routerProxy.BrokerConn0.FetchResponseFunction = FailedInFirstMessageException(exceptionType, routerProxy._cacheExpiration);
routerProxy.BrokerConn0.MetadataResponseFunction = BrokerRouterProxy.CreateMetadataResponseWithMultipleBrokers;
await protocolGateway.SendProtocolRequest(new FetchRequest(), BrokerRouterProxy.TestTopic, _partitionId);
Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(2));
Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.EqualTo(2));
}
示例12: ConsumerShouldReturnOffset
public void ConsumerShouldReturnOffset()
{
var routerProxy = new BrokerRouterProxy(_kernel);
routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };
var router = routerProxy.Create();
var options = CreateOptions(router);
options.PartitionWhitelist = new List<int>();
var consumer = new Consumer(options);
var test = consumer.Consume().Take(1);
while (consumer.ConsumerTaskCount <= 0)
{
Thread.Sleep(100);
}
Assert.That(consumer.ConsumerTaskCount, Is.EqualTo(2));
}
示例13: ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition
public void ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition()
{
var routerProxy = new BrokerRouterProxy(_kernel);
routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };
var router = routerProxy.Create();
var options = CreateOptions(router);
options.PartitionWhitelist = new List<int> { 0 };
var consumer = new Consumer(options);
var test = consumer.Consume().Take(1);
while (consumer.ConsumerTaskCount <= 0)
{
Thread.Sleep(100);
}
Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.GreaterThanOrEqualTo(1));
Assert.That(routerProxy.BrokerConn1.FetchRequestCallCount, Is.EqualTo(0));
}
示例14: ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition
public void ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition()
{
var routerProxy = new BrokerRouterProxy(new MoqMockingKernel());
routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };
var router = routerProxy.Create();
var options = CreateOptions(router);
options.PartitionWhitelist = new List<int> { 0 };
using (var consumer = new Consumer(options))
{
var test = consumer.Consume();
TaskTest.WaitFor(() => consumer.ConsumerTaskCount > 0);
TaskTest.WaitFor(() => routerProxy.BrokerConn0.FetchRequestCallCount > 0);
Assert.That(consumer.ConsumerTaskCount, Is.EqualTo(1), "Consumer should only create one consuming thread for partition 0.");
Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.GreaterThanOrEqualTo(1));
Assert.That(routerProxy.BrokerConn1.FetchRequestCallCount, Is.EqualTo(0));
}
}
示例15: ConnectionExceptionOnOneShouldCommunicateBackWhichMessagesFailed
public void ConnectionExceptionOnOneShouldCommunicateBackWhichMessagesFailed()
{
//TODO is there a way to communicate back which client failed and which succeeded.
var routerProxy = new BrokerRouterProxy(_kernel);
routerProxy.BrokerConn1.ProduceResponseFunction = () => { throw new ApplicationException("some exception"); };
var router = routerProxy.Create();
var producer = new Producer(router);
var messages = new List<Message>
{
new Message{Value = "1"}, new Message{Value = "2"}
};
//this will produce an exception, but message 1 succeeded and message 2 did not.
//should we return a ProduceResponse with an error and no error for the other messages?
//at this point though the client does not know which message is routed to which server.
//the whole batch of messages would need to be returned.
var test = producer.SendMessageAsync("UnitTest", messages).Result;
}