use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestLiSymbolTableProvider method testGetRemoteSymbolTableFetchSuccess.
@Test
public void testGetRemoteSymbolTableFetchSuccess() throws IOException {
RestResponseBuilder builder = new RestResponseBuilder();
builder.setStatus(200);
SymbolTable symbolTable = new InMemorySymbolTable("https://OtherHost:100/service|Test--332004310", Collections.unmodifiableList(Arrays.asList("Haha", "Hehe")));
builder.setEntity(SymbolTableSerializer.toByteString(ContentType.PROTOBUF2.getCodec(), symbolTable));
builder.setHeader(RestConstants.HEADER_CONTENT_TYPE, ContentType.PROTOBUF2.getHeaderKey());
when(_client.restRequest(eq(new RestRequestBuilder(URI.create("https://OtherHost:100/service/symbolTable/Test--332004310")).setHeaders(Collections.singletonMap(RestConstants.HEADER_FETCH_SYMBOL_TABLE, Boolean.TRUE.toString())).build()))).thenReturn(CompletableFuture.completedFuture(builder.build()));
SymbolTable remoteSymbolTable = _provider.getSymbolTable("https://OtherHost:100/service|Test--332004310");
Assert.assertNotNull(remoteSymbolTable);
Assert.assertEquals("https://Host:100/service|Test--332004310", remoteSymbolTable.getName());
Assert.assertEquals(2, remoteSymbolTable.size());
// Subsequent fetch should not trigger network fetch and get the table from the cache.
when(_client.restRequest(any(RestRequest.class))).thenThrow(new IllegalStateException());
SymbolTable cachedSymbolTable = _provider.getSymbolTable("https://OtherHost:100/service|Test--332004310");
Assert.assertSame(remoteSymbolTable, cachedSymbolTable);
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestLiSymbolTableProvider method testGetRemoteRequestSymbolTableFetchSuccess.
@Test
public void testGetRemoteRequestSymbolTableFetchSuccess() throws IOException {
RestResponseBuilder builder = new RestResponseBuilder();
builder.setStatus(200);
SymbolTable symbolTable = new InMemorySymbolTable("https://OtherHost:100/service|Test--332004310", Collections.unmodifiableList(Arrays.asList("Haha", "Hehe")));
builder.setEntity(SymbolTableSerializer.toByteString(ContentType.PROTOBUF2.getCodec(), symbolTable));
builder.setHeader(RestConstants.HEADER_CONTENT_TYPE, ContentType.PROTOBUF2.getHeaderKey());
when(_client.restRequest(eq(new RestRequestBuilder(URI.create("d2://someservice/symbolTable")).setHeaders(Collections.singletonMap(RestConstants.HEADER_FETCH_SYMBOL_TABLE, Boolean.TRUE.toString())).build()))).thenReturn(CompletableFuture.completedFuture(builder.build()));
SymbolTable remoteSymbolTable = _provider.getRequestSymbolTable(URI.create("d2://someservice/path"));
Assert.assertNotNull(remoteSymbolTable);
Assert.assertEquals("https://Host:100/service|Test--332004310", remoteSymbolTable.getName());
Assert.assertEquals(2, remoteSymbolTable.size());
// Subsequent fetch should not trigger network fetch and get the table from the cache, regardless of
// whether the table is fetched by request URI or symbol table name.
when(_client.restRequest(any(RestRequest.class))).thenThrow(new IllegalStateException());
SymbolTable cachedSymbolTable = _provider.getRequestSymbolTable(URI.create("d2://someservice/path"));
Assert.assertSame(remoteSymbolTable, cachedSymbolTable);
cachedSymbolTable = _provider.getSymbolTable("https://OtherHost:100/service|Test--332004310");
Assert.assertSame(remoteSymbolTable, cachedSymbolTable);
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestDarkClusterVerifierManager method testVerifierEnabled.
@Test
public void testVerifierEnabled() throws InterruptedException {
setup(true);
RestRequest dummyRestRequest = new RestRequestBuilder(URI.create("foo")).build();
RestResponse res = new RestResponseBuilder().build();
_verifierManager.onDarkResponse(dummyRestRequest, res, DARK_CLUSTER1_NAME);
_verifierManager.onDarkResponse(dummyRestRequest, res, DARK_CLUSTER1_NAME);
_verifierManager.onResponse(dummyRestRequest, res);
waitForLatch();
Assert.assertEquals(_verifier.onResponseCount, 1, "expected on response count of 1");
Assert.assertEquals(_verifier.onDarkResponseCount, 2, "expected on dark response count of 2");
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestDarkClusterVerifierManager method testVerifierDisabled.
@Test
void testVerifierDisabled() throws InterruptedException {
setup(false);
RestRequest req = new RestRequestBuilder(URI.create("foo")).build();
RestResponse res = new RestResponseBuilder().build();
_verifierManager.onDarkResponse(req, res, DARK_CLUSTER1_NAME);
_verifierManager.onDarkResponse(req, res, DARK_CLUSTER1_NAME);
_verifierManager.onResponse(req, res);
waitForLatch();
Assert.assertEquals(_verifier.onResponseCount, 0, "expected on response count of 0");
Assert.assertEquals(_verifier.onDarkResponseCount, 0, "expected on dark response count of 0");
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestDarkClusterFilter method testDarkClusterAssemblyWithDarkCluster.
@Test
public void testDarkClusterAssemblyWithDarkCluster() {
// we need to have a Mock clusterInfoProvider in order to set up a dark cluster.
MockClusterInfoProvider clusterInfoProvider = new MockClusterInfoProvider();
_facilities = new MockFacilities(clusterInfoProvider);
_darkClusterStrategyFactory = new DarkClusterStrategyFactoryImpl(_facilities, SOURCE_CLUSTER_NAME, _darkClusterDispatcher, _notifier, _random, _verifierManager, _rateLimiterSupplier);
_darkClusterStrategyFactory.start();
DarkClusterManager darkClusterManager = new DarkClusterManagerImpl(SOURCE_CLUSTER_NAME, _facilities, _darkClusterStrategyFactory, "", "", _notifier);
_darkClusterFilter = new DarkClusterFilter(darkClusterManager, _verifierManager);
// set the multiplier to 1 so that traffic gets sent.
DarkClusterConfig darkClusterConfig = createRelativeTrafficMultiplierConfig(1.0f);
clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig);
clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
// send the request, expecting it to make it all the way down to the client
RestRequest restRequest = new RestRequestBuilder(URI.create("foo")).build();
_darkClusterFilter.onRestRequest(restRequest, new RequestContext(), new HashMap<>(), new DummyNextFilter());
Assert.assertEquals(_client.requestAuthorityMap.size(), 1, "expected 1 request to be sent");
_darkClusterFilter.onRestError(new RuntimeException("test"), new RequestContext(), new HashMap<>(), new DummyNextFilter());
_darkClusterFilter.onRestResponse(new RestResponseBuilder().build(), new RequestContext(), new HashMap<>(), new DummyNextFilter());
}
Aggregations