use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestAsyncInvoke method check.
/**
* Wait for response and check
*/
private <T> void check(CompletableFuture<ResponseEntity<T>> responseEntityCompletableFuture, BiConsumer<ResponseEntity<T>, Throwable> checkLogic) {
CountDownLatch countDownLatch = new CountDownLatch(1);
Holder<Boolean> responseChecked = new Holder<>();
responseEntityCompletableFuture.whenComplete((responseEntity, ex) -> {
checkLogic.accept(responseEntity, ex);
responseChecked.value = true;
countDownLatch.countDown();
});
try {
countDownLatch.await(3000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
fail("error occurs while waiting for response, " + e.getMessage());
}
Assert.assertTrue("response check unfinished!", responseChecked.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestPartToMultipartFile method transferTo.
@Test
public void transferTo() throws IllegalStateException, IOException {
File dest = new File("/dest");
Holder<String> destName = new Holder<>();
new MockUp<Part>(part) {
@Mock
void write(String fileName) throws IOException {
destName.value = fileName;
}
};
multipartFile.transferTo(dest);
Assert.assertEquals(dest.getPath(), destName.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestDefaultLogPublisher method init_enabled_default.
@Test
public void init_enabled_default() {
Holder<Boolean> registered = new Holder<>(false);
new MockUp<EventBus>(eventBus) {
@Mock
void register(Object object) {
registered.value = true;
}
};
publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
Assert.assertFalse(registered.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestDefaultLogPublisher method init_enabled_false.
@Test
public void init_enabled_false() {
Holder<Boolean> registered = new Holder<>();
new MockUp<EventBus>(eventBus) {
@Mock
void register(Object object) {
registered.value = true;
}
};
ArchaiusUtils.setProperty(DefaultLogPublisher.ENABLED, false);
publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
Assert.assertNull(registered.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method invokeFilterHaveResponse.
@Test
public void invokeFilterHaveResponse(@Mocked HttpServerFilter filter) {
Response response = Response.ok("");
new Expectations() {
{
filter.enabled();
result = true;
filter.afterReceiveRequest(invocation, requestEx);
result = response;
}
};
Holder<Response> result = new Holder<>();
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void doInvoke() {
result.value = Response.ok("not run to here");
}
@Override
protected void sendResponseQuietly(Response response) {
result.value = response;
}
};
initRestInvocation();
restInvocation.httpServerFilters = Arrays.asList(filter);
restInvocation.invoke();
Assert.assertSame(response, result.value);
}
Aggregations