use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class ClientFilterTest method testCustomResourceName.
@Test
public void testCustomResourceName() {
final String url = "/test/hello/{name}";
final String resourceName = "GET:" + url;
Response response1 = SentinelJaxRsClientTemplate.execute(resourceName, new Supplier<Response>() {
@Override
public Response get() {
return client.target(host).path(url).resolveTemplate("name", "abc").request().get();
}
});
assertEquals(200, response1.getStatus());
assertEquals("Hello abc !", response1.readEntity(String.class));
Response response2 = SentinelJaxRsClientTemplate.execute(resourceName, new Supplier<Response>() {
@Override
public Response get() {
return client.target(host).path(url).resolveTemplate("name", "def").request().get();
}
});
assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response2.getStatus());
assertEquals("Hello def !", response2.readEntity(String.class));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(2, cn.passQps(), 0.01);
assertNull(ClusterBuilderSlot.getClusterNode("/test/hello/abc"));
assertNull(ClusterBuilderSlot.getClusterNode("/test/hello/def"));
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class ClientFilterTest method testServerTimeout.
@Test
public void testServerTimeout() {
final String url = "/test/delay/10";
final String resourceName = "GET:/test/delay/{seconds}";
try {
SentinelJaxRsClientTemplate.execute(resourceName, new Supplier<Response>() {
@Override
public Response get() {
return client.target(host).path(url).request().get();
}
});
} catch (ProcessingException e) {
// ignore
}
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(0, cn.passQps(), 0.01);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class ClientFilterTest method testFutureGetServerTimeout.
@Test
public void testFutureGetServerTimeout() {
final String url = "/test/delay/10";
final String resourceName = "GET:/test/delay/{seconds}";
try {
Future<Response> future = SentinelJaxRsClientTemplate.executeAsync(resourceName, new Supplier<Future<Response>>() {
@Override
public Future<Response> get() {
return client.target(host).path(url).request().async().get();
}
});
future.get();
} catch (Exception e) {
// ignore
}
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(0, cn.passQps(), 0.01);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class ClientFilterTest method testFutureGetTimeout.
@Test
public void testFutureGetTimeout() {
final String url = "/test/delay/10";
final String resourceName = "GET:/test/delay/{seconds}";
try {
Future<Response> future = SentinelJaxRsClientTemplate.executeAsync(resourceName, new Supplier<Future<Response>>() {
@Override
public Future<Response> get() {
return client.target(host).path(url).request().async().get();
}
});
future.get(1, TimeUnit.SECONDS);
} catch (Exception e) {
// ignore
}
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(0, cn.passQps(), 0.01);
}
use of com.alibaba.csp.sentinel.node.ClusterNode in project Sentinel by alibaba.
the class ClientFilterTest method testClientAsyncGetHello.
@Test
public void testClientAsyncGetHello() throws InterruptedException, ExecutionException {
final String url = "/test/async-hello";
final String resourceName = "GET:" + url;
Future<Response> future = SentinelJaxRsClientTemplate.executeAsync(resourceName, new Supplier<Future<Response>>() {
@Override
public Future<Response> get() {
return client.target(host).path(url).request().async().get();
}
});
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(HELLO_STR, future.get().readEntity(String.class));
cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
}
Aggregations