Search in sources :

Example 11 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore 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));
    }
}
Also used : ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) CookieStore(org.asynchttpclient.cookie.CookieStore) CookieEvictionTask(org.asynchttpclient.cookie.CookieEvictionTask) Timer(io.netty.util.Timer) TimeUnit(java.util.concurrent.TimeUnit) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Test(org.testng.annotations.Test)

Example 12 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore 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));
    }
}
Also used : ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) CookieStore(org.asynchttpclient.cookie.CookieStore) CookieEvictionTask(org.asynchttpclient.cookie.CookieEvictionTask) Timer(io.netty.util.Timer) TimeUnit(java.util.concurrent.TimeUnit) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Test(org.testng.annotations.Test)

Example 13 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore 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);
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Uri(org.asynchttpclient.uri.Uri) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 14 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore 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);
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 15 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore 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);
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Uri(org.asynchttpclient.uri.Uri) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Aggregations

ThreadSafeCookieStore (org.asynchttpclient.cookie.ThreadSafeCookieStore)34 CookieStore (org.asynchttpclient.cookie.CookieStore)33 Uri (org.asynchttpclient.uri.Uri)16 Test (org.testng.annotations.Test)5 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)3 Timer (io.netty.util.Timer)3 TimeUnit (java.util.concurrent.TimeUnit)3 CookieEvictionTask (org.asynchttpclient.cookie.CookieEvictionTask)3 Sets (com.google.common.collect.Sets)2 ClientCookieDecoder (io.netty.handler.codec.http.cookie.ClientCookieDecoder)2 ClientCookieEncoder (io.netty.handler.codec.http.cookie.ClientCookieEncoder)2 Cookie (io.netty.handler.codec.http.cookie.Cookie)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Assert.assertTrue (org.testng.Assert.assertTrue)2 AfterClass (org.testng.annotations.AfterClass)2 BeforeClass (org.testng.annotations.BeforeClass)2