use of com.dtflys.forest.backend.HttpBackend in project forest by dromara.
the class TestPoolClient method testPool.
@Test
public void testPool() throws InterruptedException {
int count = 100;
for (int i = 0; i < count; i++) {
server.enqueue(new MockResponse().setBody(EXPECTED).setHeadersDelay(1, TimeUnit.SECONDS));
}
HttpBackend backend = configuration.getBackend();
ForestConnectionManager connectionManager = backend.getConnectionManager();
ExecutorService executorService = Executors.newFixedThreadPool(count);
CountDownLatch latch = new CountDownLatch(count);
for (int i = 0; i < count; i++) {
executorService.execute(() -> {
poolClient.send();
if (connectionManager instanceof OkHttp3ConnectionManager) {
ConnectionPool pool = ((OkHttp3ConnectionManager) connectionManager).getOkHttpPool();
System.out.println("connect count = " + pool.connectionCount());
}
latch.countDown();
});
}
latch.await();
}
use of com.dtflys.forest.backend.HttpBackend in project forest by dromara.
the class TestForestConfiguration method testBackend.
@Test
public void testBackend() {
ForestConfiguration configuration = ForestConfiguration.createConfiguration();
configuration.setBackendName("okhttp3");
assertEquals("okhttp3", configuration.getBackend().getName());
configuration.setBackend(null);
configuration.setBackendName("httpclient");
assertEquals("httpclient", configuration.getBackend().getName());
HttpBackendSelector originSelector = new HttpBackendSelector();
HttpBackendSelector selector = Mockito.spy(originSelector);
configuration.setHttpBackendSelector(selector);
Mockito.when(selector.findOkHttp3BackendInstance()).thenReturn(null);
configuration.setBackendName(null);
configuration.setBackend(null);
Assert.assertEquals("httpclient", configuration.getBackend().getName());
Mockito.when(selector.findHttpclientBackendInstance()).thenReturn(null);
configuration.setBackendName(null);
configuration.setBackend(null);
boolean thrown = false;
try {
HttpBackend backend = configuration.getBackend();
System.out.print(backend);
} catch (ForestRuntimeException e) {
thrown = true;
}
assertTrue(thrown);
}
use of com.dtflys.forest.backend.HttpBackend in project forest by dromara.
the class ForestRequest method setBackend.
/**
* 设置HTTP后端框架
*
* @param backendName Forest后端框架名称
* @return {@link ForestRequest}对象实例
*/
public ForestRequest<T> setBackend(String backendName) {
HttpBackend backend = configuration.getBackendSelector().select(backendName);
if (backend != null) {
backend.init(configuration);
this.backend = backend;
}
return this;
}
use of com.dtflys.forest.backend.HttpBackend in project forest by dromara.
the class Test0 method testRetry.
@Test
public void testRetry() {
ForestLogger logger = Mockito.mock(ForestLogger.class);
config0.getLogHandler().setLogger(logger);
try {
beastshopClient.testRetry();
} catch (ForestRuntimeException e) {
}
HttpBackend backend = config0.getBackend();
String backendName = backend.getName();
Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 1\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 2\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 3\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 4\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 5\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
// Mockito.verify(logger).info("[Forest] [Network Error]: connect timed out");
}
Aggregations