Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8087b6

Browse files
Merge pull request#1585 from rabbitmq/rabbitmq-dotnet-client-1038
2 parents137abc9 +7005353 commitf8087b6

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 2.0.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (c) 2007-2020 VMware, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// https://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v2.0:
23+
//
24+
//---------------------------------------------------------------------------
25+
// This Source Code Form is subject to the terms of the Mozilla Public
26+
// License, v. 2.0. If a copy of the MPL was not distributed with this
27+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
28+
//
29+
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
30+
//---------------------------------------------------------------------------
31+
32+
usingSystem;
33+
usingSystem.Threading;
34+
usingSystem.Threading.Tasks;
35+
usingRabbitMQ.Client;
36+
usingRabbitMQ.Client.Events;
37+
usingXunit;
38+
usingXunit.Abstractions;
39+
40+
namespaceTest.Integration
41+
{
42+
publicclassTestAsyncEventingBasicConsumer:IntegrationFixture
43+
{
44+
privatereadonlyCancellationTokenSource_cts=newCancellationTokenSource(ShortSpan);
45+
privatereadonlyCancellationTokenRegistration_ctr;
46+
privatereadonlyTaskCompletionSource<bool>_onCallbackExceptionTcs=
47+
newTaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
48+
privatereadonlyTaskCompletionSource<bool>_onReceivedTcs=
49+
newTaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
50+
51+
publicTestAsyncEventingBasicConsumer(ITestOutputHelperoutput)
52+
:base(output,dispatchConsumersAsync:true,consumerDispatchConcurrency:2)
53+
{
54+
_ctr=_cts.Token.Register(OnTokenCanceled);
55+
}
56+
57+
publicoverrideTaskDisposeAsync()
58+
{
59+
_ctr.Dispose();
60+
_cts.Dispose();
61+
returnbase.DisposeAsync();
62+
}
63+
64+
privatevoidOnTokenCanceled()
65+
{
66+
_onCallbackExceptionTcs.TrySetCanceled();
67+
_onReceivedTcs.TrySetCanceled();
68+
}
69+
70+
privatevoidConsumerChannelOnCallbackException(objectsender,CallbackExceptionEventArgse)
71+
{
72+
_onCallbackExceptionTcs.TrySetResult(true);
73+
}
74+
75+
privateTaskAsyncConsumerOnReceived(objectsender,BasicDeliverEventArgs@event)
76+
{
77+
_onReceivedTcs.TrySetResult(true);
78+
thrownewException("from async subscriber");
79+
}
80+
81+
[Fact]
82+
publicasyncTaskTestAsyncEventingBasicConsumer_GH1038()
83+
{
84+
stringexchangeName=GenerateExchangeName();
85+
stringqueueName=GenerateQueueName();
86+
stringroutingKey=string.Empty;
87+
88+
await_channel.ExchangeDeclareAsync(exchangeName,ExchangeType.Direct);
89+
await_channel.QueueDeclareAsync(queueName,false,false,true,null);
90+
await_channel.QueueBindAsync(queueName,exchangeName,routingKey,null);
91+
92+
_channel.CallbackException+=ConsumerChannelOnCallbackException;
93+
94+
//async subscriber
95+
varconsumer=newAsyncEventingBasicConsumer(_channel);
96+
consumer.Received+=AsyncConsumerOnReceived;
97+
await_channel.BasicConsumeAsync(queueName,false,consumer);
98+
99+
//publisher
100+
usingIChannelpublisherChannel=await_conn.CreateChannelAsync();
101+
byte[]messageBodyBytes=System.Text.Encoding.UTF8.GetBytes("Hello, world!");
102+
varprops=newBasicProperties();
103+
awaitpublisherChannel.BasicPublishAsync(exchangeName,"",props,messageBodyBytes);
104+
105+
awaitTask.WhenAll(_onReceivedTcs.Task,_onCallbackExceptionTcs.Task);
106+
Assert.True(await_onReceivedTcs.Task);
107+
Assert.True(await_onCallbackExceptionTcs.Task);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp