use of org.asynchttpclient.cookie.CookieStore in project async-http-client by AsyncHttpClient.
the class DefaultAsyncHttpClientTest method testWithSharedCookieStoreButNonSharedTimerShouldScheduleCookieEvictionForFirstAHC.
@Test
public void testWithSharedCookieStoreButNonSharedTimerShouldScheduleCookieEvictionForFirstAHC() throws IOException {
CookieStore cookieStore = new ThreadSafeCookieStore();
Timer nettyTimerMock1 = mock(Timer.class);
AsyncHttpClientConfig config1 = config().setCookieStore(cookieStore).setNettyTimer(nettyTimerMock1).build();
try (AsyncHttpClient client1 = asyncHttpClient(config1)) {
Timer nettyTimerMock2 = mock(Timer.class);
AsyncHttpClientConfig config2 = config().setCookieStore(cookieStore).setNettyTimer(nettyTimerMock2).build();
try (AsyncHttpClient client2 = asyncHttpClient(config2)) {
assertEquals(config1.getCookieStore().count(), 2);
verify(nettyTimerMock1, times(1)).newTimeout(any(CookieEvictionTask.class), anyLong(), any(TimeUnit.class));
verify(nettyTimerMock2, never()).newTimeout(any(CookieEvictionTask.class), anyLong(), any(TimeUnit.class));
}
}
Timer nettyTimerMock3 = mock(Timer.class);
AsyncHttpClientConfig config3 = config().setCookieStore(cookieStore).setNettyTimer(nettyTimerMock3).build();
try (AsyncHttpClient client2 = asyncHttpClient(config3)) {
assertEquals(config1.getCookieStore().count(), 1);
verify(nettyTimerMock3, times(1)).newTimeout(any(CookieEvictionTask.class), anyLong(), any(TimeUnit.class));
}
}
use of org.asynchttpclient.cookie.CookieStore in project async-http-client by AsyncHttpClient.
the class DefaultAsyncHttpClientTest method testWithSharedCookieStoreButNonSharedTimerShouldReScheduleCookieEvictionWhenFirstInstanceGetClosed.
@Test
public void testWithSharedCookieStoreButNonSharedTimerShouldReScheduleCookieEvictionWhenFirstInstanceGetClosed() throws IOException {
CookieStore cookieStore = new ThreadSafeCookieStore();
Timer nettyTimerMock1 = mock(Timer.class);
AsyncHttpClientConfig config1 = config().setCookieStore(cookieStore).setNettyTimer(nettyTimerMock1).build();
try (AsyncHttpClient client1 = asyncHttpClient(config1)) {
assertEquals(config1.getCookieStore().count(), 1);
verify(nettyTimerMock1, times(1)).newTimeout(any(CookieEvictionTask.class), anyLong(), any(TimeUnit.class));
}
assertEquals(config1.getCookieStore().count(), 0);
Timer nettyTimerMock2 = mock(Timer.class);
AsyncHttpClientConfig config2 = config().setCookieStore(cookieStore).setNettyTimer(nettyTimerMock2).build();
try (AsyncHttpClient client2 = asyncHttpClient(config2)) {
assertEquals(config1.getCookieStore().count(), 1);
verify(nettyTimerMock2, times(1)).newTimeout(any(CookieEvictionTask.class), anyLong(), any(TimeUnit.class));
}
}
use of org.asynchttpclient.cookie.CookieStore in project async-http-client by AsyncHttpClient.
the class CookieStoreTest method addCookieWithEmptyPath.
private void addCookieWithEmptyPath() {
CookieStore store = new ThreadSafeCookieStore();
Uri uri = Uri.create("http://www.foo.com");
store.add(uri, ClientCookieDecoder.LAX.decode("ALPHA=VALUE1; path="));
assertTrue(store.get(uri).size() > 0);
}
use of org.asynchttpclient.cookie.CookieStore in project async-http-client by AsyncHttpClient.
the class CookieStoreTest method returnTheCookieWheniTSissuedFromRequestWithSubpath.
private void returnTheCookieWheniTSissuedFromRequestWithSubpath() {
CookieStore store = new ThreadSafeCookieStore();
store.add(Uri.create("http://www.foo.com/bar"), ClientCookieDecoder.LAX.decode("ALPHA=VALUE; path=/"));
assertTrue(store.get(Uri.create("http://www.foo.com")).size() == 1);
}
use of org.asynchttpclient.cookie.CookieStore in project async-http-client by AsyncHttpClient.
the class CookieStoreTest method dontReplaceCookiesWhenTheyHaveDifferentName.
private void dontReplaceCookiesWhenTheyHaveDifferentName() {
CookieStore store = new ThreadSafeCookieStore();
Uri uri = Uri.create("http://www.foo.com/bar/baz");
store.add(uri, ClientCookieDecoder.LAX.decode("BETA=VALUE1; Domain=www.foo.com; path=/bar"));
store.add(uri, ClientCookieDecoder.LAX.decode("ALPHA=VALUE2; Domain=www.foo.com; path=/bar"));
assertTrue(store.get(uri).size() == 2);
}
Aggregations