Search in sources :

Example 16 with Reply

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project RxCache by VictorAlbertos.

the class ProvidersRxCacheTest method _11_When_Retrieve_Cached_Data_After_Modified_Object_On_Item_Array_Then_Object_Preserves_Initial_State.

@Test
public void _11_When_Retrieve_Cached_Data_After_Modified_Object_On_Item_Array_Then_Object_Preserves_Initial_State() {
    initProviders(false);
    TestObserver<Reply<io.rx_cache2.internal.Mock[]>> subscriber;
    subscriber = new TestObserver<>();
    providersRxCache.getMocksArrayResponse(createObservableMocksArray(SIZE)).subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    Reply<io.rx_cache2.internal.Mock[]> reply = subscriber.values().get(0);
    Type type = new TypeToken<Reply<io.rx_cache2.internal.Mock[]>>() {
    }.getType();
    Reply<io.rx_cache2.internal.Mock[]> replyOriginal = (Reply<io.rx_cache2.internal.Mock[]>) deepCopy(reply, type);
    assertThat(compare(reply, replyOriginal, type), is(true));
    reply.getData()[0].setMessage("modified");
    assertThat(compare(reply, replyOriginal, type), is(false));
    subscriber = new TestObserver<>();
    providersRxCache.getMocksArrayResponse(ProviderHelper.<io.rx_cache2.internal.Mock[]>withoutLoader()).subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    assertThat(subscriber.errors().size(), is(0));
    assertThat(subscriber.values().size(), is(1));
    reply = subscriber.values().get(0);
    type = new TypeToken<io.rx_cache2.internal.Mock[]>() {
    }.getType();
    assertThat(compare(reply.getData(), replyOriginal.getData(), type), is(true));
}
Also used : Type(java.lang.reflect.Type) TypeToken(com.google.gson.reflect.TypeToken) Reply(io.rx_cache2.Reply) Test(org.junit.Test)

Example 17 with Reply

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project RxCache by VictorAlbertos.

the class ProvidersDynamicsKeysRxCacheTest method Pagination_With_Evict_Cache_By_Page.

@Test
public void Pagination_With_Evict_Cache_By_Page() {
    TestObserver<Reply<List<io.rx_cache2.internal.Mock>>> observer;
    observer = providersRxCache.getMocksDynamicKeyEvictPage(Observable.just(createMocks(SIZE)), new DynamicKey(1), new EvictDynamicKey(true)).test();
    observer.awaitTerminalEvent();
    observer = providersRxCache.getMocksDynamicKeyEvictPage(Observable.just(createMocks(SIZE)), new DynamicKey(2), new EvictDynamicKey(true)).test();
    observer.awaitTerminalEvent();
    observer = providersRxCache.getMocksDynamicKeyEvictPage(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(1), new EvictDynamicKey(true)).test();
    observer.awaitTerminalEvent();
    assertThat(observer.errors().size(), is(1));
    assertThat(observer.values().size(), is(0));
    observer = providersRxCache.getMocksDynamicKeyEvictPage(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(2), new EvictDynamicKey(false)).test();
    observer.awaitTerminalEvent();
    assertThat(observer.errors().size(), is(0));
    assertThat(observer.values().size(), is(1));
}
Also used : EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Example 18 with Reply

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply in project jargyle by jh3nd3rs0n.

the class Socks5HostResolver method resolve.

@Override
public InetAddress resolve(final String host) throws IOException {
    if (host == null) {
        return InetAddress.getLoopbackAddress();
    }
    Properties properties = this.socks5Client.getProperties();
    AddressType addressType = AddressType.valueForString(host);
    if (!addressType.equals(AddressType.DOMAINNAME) || !properties.getValue(Socks5PropertySpecConstants.SOCKS5_RESOLVE_USE_RESOLVE_COMMAND).booleanValue()) {
        return InetAddress.getByName(host);
    }
    Socket socket = this.socks5Client.newInternalSocket();
    this.socks5Client.configureInternalSocket(socket);
    Socket sock = this.socks5Client.getConnectedInternalSocket(socket, true);
    Method method = this.socks5Client.negotiateMethod(sock);
    MethodEncapsulation methodEncapsulation = this.socks5Client.doMethodSubnegotiation(method, sock);
    Socket sck = methodEncapsulation.getSocket();
    Socks5Request socks5Req = Socks5Request.newInstance(Command.RESOLVE, host, 0);
    this.socks5Client.sendSocks5Request(socks5Req, sck);
    Socks5Reply socks5Rep = null;
    try {
        socks5Rep = this.socks5Client.receiveSocks5Reply(sck);
    } catch (FailureSocks5ReplyException e) {
        Reply reply = e.getFailureSocks5Reply().getReply();
        if (reply.equals(Reply.HOST_UNREACHABLE)) {
            throw new UnknownHostException(host);
        } else {
            throw e;
        }
    }
    InetAddress inetAddress = InetAddress.getByName(socks5Rep.getServerBoundAddress());
    return InetAddress.getByAddress(host, inetAddress.getAddress());
}
Also used : MethodEncapsulation(com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation) Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) UnknownHostException(java.net.UnknownHostException) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) Properties(com.github.jh3nd3rs0n.jargyle.client.Properties) AddressType(com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Aggregations

Reply (io.rx_cache2.Reply)16 Function (io.reactivex.functions.Function)9 FavoriteException (com.dante.exception.FavoriteException)7 MessageException (com.dante.exception.MessageException)7 EvictDynamicKey (io.rx_cache2.EvictDynamicKey)7 Test (org.junit.Test)7 BaseResult (com.dante.data.model.BaseResult)6 DynamicKeyGroup (io.rx_cache2.DynamicKeyGroup)6 EvictDynamicKeyGroup (io.rx_cache2.EvictDynamicKeyGroup)6 UnLimit91PornItem (com.dante.data.model.UnLimit91PornItem)4 TypeToken (com.google.gson.reflect.TypeToken)3 TestObserver (io.reactivex.observers.TestObserver)3 DynamicKey (io.rx_cache2.DynamicKey)3 BaseTest (io.rx_cache2.internal.common.BaseTest)3 Type (java.lang.reflect.Type)3 Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply)2 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)2 MeiZiTu (com.dante.data.model.MeiZiTu)1 Mm99 (com.dante.data.model.Mm99)1 PigAvVideo (com.dante.data.model.PigAvVideo)1