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));
}
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));
}
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());
}
Aggregations