4
4
import org .asynchttpclient .cookie .CookieEvictionTask ;
5
5
import org .asynchttpclient .cookie .CookieStore ;
6
6
import org .asynchttpclient .cookie .ThreadSafeCookieStore ;
7
- import org .testng .annotations .Test ;
8
7
9
8
import java .io .IOException ;
10
9
import java .util .concurrent .TimeUnit ;
10
+ import org .junit .Test ;
11
11
12
- import static org .asynchttpclient . Dsl .* ;
12
+ import static org .junit . Assert . assertEquals ;
13
13
import static org .mockito .ArgumentMatchers .any ;
14
14
import static org .mockito .ArgumentMatchers .anyLong ;
15
15
import static org .mockito .Mockito .*;
16
- import static org .testng .Assert .assertEquals ;
17
16
18
17
public class DefaultAsyncHttpClientTest {
19
18
20
19
@ Test
21
20
public void testWithSharedNettyTimerShouldScheduleCookieEvictionOnlyOnce () throws IOException {
22
21
Timer nettyTimerMock = mock (Timer .class );
23
22
CookieStore cookieStore = new ThreadSafeCookieStore ();
24
- AsyncHttpClientConfig config = config ().setNettyTimer (nettyTimerMock ).setCookieStore (cookieStore ).build ();
23
+ AsyncHttpClientConfig config = Dsl . config ().setNettyTimer (nettyTimerMock ).setCookieStore (cookieStore ).build ();
25
24
26
- try (AsyncHttpClient client1 = asyncHttpClient (config )) {
27
- try (AsyncHttpClient client2 = asyncHttpClient (config )) {
28
- assertEquals (cookieStore .count (), 2 );
25
+ try (AsyncHttpClient client1 = Dsl . asyncHttpClient (config )) {
26
+ try (AsyncHttpClient client2 = Dsl . asyncHttpClient (config )) {
27
+ assertEquals (2 , cookieStore .count ());
29
28
verify (nettyTimerMock , times (1 )).newTimeout (any (CookieEvictionTask .class ), anyLong (), any (TimeUnit .class ));
30
29
}
31
30
}
32
31
}
33
32
34
33
@ Test
35
34
public void testWitDefaultConfigShouldScheduleCookieEvictionForEachAHC () throws IOException {
36
- AsyncHttpClientConfig config1 = config ().build ();
37
- try (AsyncHttpClient client1 = asyncHttpClient (config1 )) {
38
- AsyncHttpClientConfig config2 = config ().build ();
39
- try (AsyncHttpClient client2 = asyncHttpClient (config2 )) {
35
+ AsyncHttpClientConfig config1 = Dsl . config ().build ();
36
+ try (AsyncHttpClient client1 = Dsl . asyncHttpClient (config1 )) {
37
+ AsyncHttpClientConfig config2 = Dsl . config ().build ();
38
+ try (AsyncHttpClient client2 = Dsl . asyncHttpClient (config2 )) {
40
39
assertEquals (config1 .getCookieStore ().count (), 1 );
41
40
assertEquals (config2 .getCookieStore ().count (), 1 );
42
41
}
@@ -47,25 +46,25 @@ public void testWitDefaultConfigShouldScheduleCookieEvictionForEachAHC() throws
47
46
public void testWithSharedCookieStoreButNonSharedTimerShouldScheduleCookieEvictionForFirstAHC () throws IOException {
48
47
CookieStore cookieStore = new ThreadSafeCookieStore ();
49
48
Timer nettyTimerMock1 = mock (Timer .class );
50
- AsyncHttpClientConfig config1 = config ()
49
+ AsyncHttpClientConfig config1 = Dsl . config ()
51
50
.setCookieStore (cookieStore ).setNettyTimer (nettyTimerMock1 ).build ();
52
51
53
- try (AsyncHttpClient client1 = asyncHttpClient (config1 )) {
52
+ try (AsyncHttpClient client1 = Dsl . asyncHttpClient (config1 )) {
54
53
Timer nettyTimerMock2 = mock (Timer .class );
55
- AsyncHttpClientConfig config2 = config ()
54
+ AsyncHttpClientConfig config2 = Dsl . config ()
56
55
.setCookieStore (cookieStore ).setNettyTimer (nettyTimerMock2 ).build ();
57
- try (AsyncHttpClient client2 = asyncHttpClient (config2 )) {
56
+ try (AsyncHttpClient client2 = Dsl . asyncHttpClient (config2 )) {
58
57
assertEquals (config1 .getCookieStore ().count (), 2 );
59
58
verify (nettyTimerMock1 , times (1 )).newTimeout (any (CookieEvictionTask .class ), anyLong (), any (TimeUnit .class ));
60
59
verify (nettyTimerMock2 , never ()).newTimeout (any (CookieEvictionTask .class ), anyLong (), any (TimeUnit .class ));
61
60
}
62
61
}
63
62
64
63
Timer nettyTimerMock3 = mock (Timer .class );
65
- AsyncHttpClientConfig config3 = config ()
64
+ AsyncHttpClientConfig config3 = Dsl . config ()
66
65
.setCookieStore (cookieStore ).setNettyTimer (nettyTimerMock3 ).build ();
67
66
68
- try (AsyncHttpClient client2 = asyncHttpClient (config3 )) {
67
+ try (AsyncHttpClient client2 = Dsl . asyncHttpClient (config3 )) {
69
68
assertEquals (config1 .getCookieStore ().count (), 1 );
70
69
verify (nettyTimerMock3 , times (1 )).newTimeout (any (CookieEvictionTask .class ), anyLong (), any (TimeUnit .class ));
71
70
}
@@ -75,31 +74,31 @@ public void testWithSharedCookieStoreButNonSharedTimerShouldScheduleCookieEvicti
75
74
public void testWithSharedCookieStoreButNonSharedTimerShouldReScheduleCookieEvictionWhenFirstInstanceGetClosed () throws IOException {
76
75
CookieStore cookieStore = new ThreadSafeCookieStore ();
77
76
Timer nettyTimerMock1 = mock (Timer .class );
78
- AsyncHttpClientConfig config1 = config ()
77
+ AsyncHttpClientConfig config1 = Dsl . config ()
79
78
.setCookieStore (cookieStore ).setNettyTimer (nettyTimerMock1 ).build ();
80
79
81
- try (AsyncHttpClient client1 = asyncHttpClient (config1 )) {
80
+ try (AsyncHttpClient client1 = Dsl . asyncHttpClient (config1 )) {
82
81
assertEquals (config1 .getCookieStore ().count (), 1 );
83
82
verify (nettyTimerMock1 , times (1 )).newTimeout (any (CookieEvictionTask .class ), anyLong (), any (TimeUnit .class ));
84
83
}
85
84
86
85
assertEquals (config1 .getCookieStore ().count (), 0 );
87
86
88
87
Timer nettyTimerMock2 = mock (Timer .class );
89
- AsyncHttpClientConfig config2 = config ()
88
+ AsyncHttpClientConfig config2 = Dsl . config ()
90
89
.setCookieStore (cookieStore ).setNettyTimer (nettyTimerMock2 ).build ();
91
90
92
- try (AsyncHttpClient client2 = asyncHttpClient (config2 )) {
91
+ try (AsyncHttpClient client2 = Dsl . asyncHttpClient (config2 )) {
93
92
assertEquals (config1 .getCookieStore ().count (), 1 );
94
93
verify (nettyTimerMock2 , times (1 )).newTimeout (any (CookieEvictionTask .class ), anyLong (), any (TimeUnit .class ));
95
94
}
96
95
}
97
96
98
97
@ Test
99
98
public void testDisablingCookieStore () throws IOException {
100
- AsyncHttpClientConfig config = config ()
99
+ AsyncHttpClientConfig config = Dsl . config ()
101
100
.setCookieStore (null ).build ();
102
- try (AsyncHttpClient client = asyncHttpClient (config )) {
101
+ try (AsyncHttpClient client = Dsl . asyncHttpClient (config )) {
103
102
//
104
103
}
105
104
}
0 commit comments