1515
1616package com .rabbitmq .client .impl ;
1717
18- import com .rabbitmq .client .Channel ;
19- import com .rabbitmq .client .Connection ;
20- import com .rabbitmq .client .ConnectionFactory ;
21- import com .rabbitmq .client .test .TestUtils ;
2218import org .junit .After ;
2319import org .junit .Test ;
2420import org .junit .runner .RunWith ;
2521import org .mockito .Mock ;
2622import org .mockito .junit .MockitoJUnitRunner ;
2723import org .mockito .stubbing .Answer ;
2824
29- import java .io .IOException ;
3025import java .time .Duration ;
3126import java .util .List ;
3227import java .util .concurrent .Callable ;
3732import java .util .function .Function ;
3833import java .util .stream .IntStream ;
3934
40- import static com .rabbitmq .client .impl .DefaultCredentialsRefreshService .*;
35+ import static com .rabbitmq .client .impl .DefaultCredentialsRefreshService .fixedDelayBeforeExpirationRefreshDelayStrategy ;
36+ import static com .rabbitmq .client .impl .DefaultCredentialsRefreshService .fixedTimeNeedRefreshStrategy ;
4137import static java .time .Duration .ofSeconds ;
4238import static org .assertj .core .api .Assertions .assertThat ;
4339import static org .mockito .Mockito .*;
@@ -60,55 +56,6 @@ public void tearDown() {
6056 }
6157 }
6258
63- @ Test public void renew () {
64- ConnectionFactory cf = new ConnectionFactory ();
65- OAuth2ClientCredentialsGrantCredentialsProvider provider = new OAuth2ClientCredentialsGrantCredentialsProvider .OAuth2ClientCredentialsGrantCredentialsProviderBuilder ()
66- .tokenEndpointUri ("http://localhost:" + 8080 + "/uaa/oauth/token" )
67- .clientId ("rabbit_client" ).clientSecret ("rabbit_secret" )
68- .grantType ("password" )
69- .parameter ("username" , "rabbit_super" )
70- .parameter ("password" , "rabbit_super" )
71- .build ();
72- cf .setCredentialsProvider (provider );
73-
74-
75- }
76-
77- @ Test public void connect () throws Exception {
78- ConnectionFactory cf = new ConnectionFactory ();
79- OAuth2ClientCredentialsGrantCredentialsProvider provider = new OAuth2ClientCredentialsGrantCredentialsProvider .OAuth2ClientCredentialsGrantCredentialsProviderBuilder ()
80- .tokenEndpointUri ("http://localhost:" + 8080 + "/uaa/oauth/token" )
81- .clientId ("rabbit_client" ).clientSecret ("rabbit_secret" )
82- .grantType ("password" )
83- .parameter ("username" , "rabbit_super" )
84- .parameter ("password" , "rabbit_super" )
85- .build ();
86- cf .setCredentialsProvider (provider );
87- refreshService = new DefaultCredentialsRefreshService .DefaultCredentialsRefreshServiceBuilder ()
88- // .refreshDelayStrategy(ttl -> Duration.ofSeconds(60))
89- .refreshDelayStrategy (ratioRefreshDelayStrategy (0.8 ))
90- .needRefreshStrategy (expiration -> false )
91- .build ();
92- cf .setCredentialsRefreshService (refreshService );
93- try (Connection c = cf .newConnection ()) {
94-
95- while (true ) {
96- try {
97- Channel ch = c .createChannel ();
98- String queue = ch .queueDeclare ().getQueue ();
99- TestUtils .sendAndConsumeMessage ("" , queue , queue , c );
100- System .out .println ("Message sent and consumed" );
101- ch .close ();
102- } catch (IOException e ) {
103- System .out .println (e .getCause ().getMessage ());
104- }
105- Thread .sleep (10_000L );
106- }
107- }
108-
109-
110- }
111-
11259 @ Test
11360 public void scheduling () throws Exception {
11461 refreshService = new DefaultCredentialsRefreshService .DefaultCredentialsRefreshServiceBuilder ()
0 commit comments