use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestHighwayTransport method testSendException.
@Test
public void testSendException() throws Exception {
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
commonHighwayMock(invocation);
Holder<Boolean> sended = new Holder<>(false);
new MockUp<HighwayClient>() {
@Mock
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
sended.value = true;
}
};
transport.send(invocation, asyncResp);
Assert.assertTrue(sended.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
the class Log4jUtilsTest method initOnMergedFileOutputDisabled.
@Test
public void initOnMergedFileOutputDisabled() {
Holder<Boolean> propertiesLoaded = new Holder<>(false);
Holder<Boolean> logConfigured = new Holder<>(false);
Holder<Boolean> mergedFileWritten = new Holder<>(false);
final Properties logProperties = new Properties();
logProperties.setProperty("log4j.logger.outputConfig.enabled", "false");
final ArrayList<Resource> logResList = new ArrayList<>();
new MockUp<PropertiesLoader>() {
@Mock
Properties load() {
propertiesLoaded.value = true;
return logProperties;
}
};
new MockUp<PropertyConfigurator>() {
@Mock
void configure(Properties properties) {
logConfigured.value = true;
Assert.assertSame(properties, logProperties);
}
};
new MockUp<Log4jUtils>() {
@Mock
void outputFile(List<Resource> resList, Properties properties) {
mergedFileWritten.value = true;
Assert.assertSame(logResList, resList);
Assert.assertSame(logProperties, properties);
}
};
Assert.assertFalse(Deencapsulation.getField(Log4jUtils.class, "inited"));
try {
Log4jUtils.init();
} catch (Exception e) {
fail(e.getMessage());
}
Assert.assertTrue(Deencapsulation.getField(Log4jUtils.class, "inited"));
Assert.assertTrue(propertiesLoaded.value);
Assert.assertTrue(logConfigured.value);
Assert.assertFalse(mergedFileWritten.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
the class DelayFaultTest method injectFaultVertxDelay.
@Test
public void injectFaultVertxDelay() throws InterruptedException {
ArchaiusUtils.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.fixedDelay", "10");
ArchaiusUtils.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.percent", "100");
assertEquals("10", DynamicProperty.getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.fixedDelay").getString());
assertEquals("100", DynamicProperty.getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.percent").getString());
DelayFault delayFault = new DelayFault();
FaultParam faultParam = new FaultParam(1);
Vertx vertx = VertxUtils.getOrCreateVertxByName("faultinjectionTest", null);
faultParam.setVertx(vertx);
Holder<String> resultHolder = new Holder<>();
CountDownLatch latch = new CountDownLatch(1);
delayFault.injectFault(invocation, faultParam, response -> {
resultHolder.value = response.getResult();
latch.countDown();
});
latch.await(10, TimeUnit.SECONDS);
AtomicLong count = FaultInjectionUtil.getOperMetTotalReq("restMicroserviceQualifiedName12");
assertEquals(1, count.get());
assertEquals("success", resultHolder.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
the class DelayFaultTest method injectFaultNoPercentageConfig.
@Test
public void injectFaultNoPercentageConfig() {
ArchaiusUtils.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.percent", null);
assertNull(DynamicProperty.getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.percent").getString());
DelayFault delayFault = new DelayFault();
FaultParam faultParam = new FaultParam(1);
Vertx vertx = VertxUtils.getOrCreateVertxByName("faultinjectionTest", null);
faultParam.setVertx(vertx);
Holder<String> resultHolder = new Holder<>();
delayFault.injectFault(invocation, faultParam, response -> resultHolder.value = response.getResult());
AtomicLong count = FaultInjectionUtil.getOperMetTotalReq("restMicroserviceQualifiedName12");
assertEquals(1, count.get());
assertEquals("success", resultHolder.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
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);
}
Aggregations