use of com.ctrip.xpipe.exception.XpipeRuntimeException in project x-pipe by ctripcorp.
the class DefaultDelayMonitorTest2 method notifyCollectors.
@Test
public void notifyCollectors() throws Exception {
Mockito.doThrow(new XpipeRuntimeException("Collector 1")).when(collector1).collect(any());
Mockito.doThrow(new XpipeRuntimeException("Collector 2")).when(collector2).collect(any());
Mockito.doThrow(new XpipeRuntimeException("Collector 3")).when(collector3).collect(any());
monitor.notifyCollectors(sample);
verify(collector1).collect(any());
verify(collector2).collect(any());
verify(collector3).collect(any());
}
use of com.ctrip.xpipe.exception.XpipeRuntimeException in project x-pipe by ctripcorp.
the class SpringComponentLifecycleManager method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent) {
try {
logger.info("[onApplicationEvent][ContextRefreshedEvent, startAll]");
startAll();
} catch (Exception e) {
throw new XpipeRuntimeException("[startAll][fail]", e);
}
}
if (event instanceof ContextClosedEvent) {
try {
logger.info("[onApplicationEvent][ContextClosedEvent, stopAll]");
stopAll();
} catch (Exception e) {
logger.error("[onApplicationEvent][stop all]", e);
throw new XpipeRuntimeException("[stopAll][fail]", e);
}
}
}
use of com.ctrip.xpipe.exception.XpipeRuntimeException in project x-pipe by ctripcorp.
the class ClusterServiceImpl method balanceCluster.
// Add transaction for one cluster update, rollback if one 'DcClusterShard' update fails
@VisibleForTesting
@DalTransaction
protected void balanceCluster(Map<String, List<SetinelTbl>> dcToSentinels, final String cluster) {
for (String dcName : dcToSentinels.keySet()) {
List<DcClusterShardTbl> dcClusterShards = dcClusterShardService.findAllByDcCluster(dcName, cluster);
List<SetinelTbl> sentinels = dcToSentinels.get(dcName);
if (dcClusterShards == null || sentinels == null) {
throw new XpipeRuntimeException("DcClusterShard | Sentinels should not be null");
}
long randomlySelectedSentinelId = randomlyChoseSentinels(sentinels);
dcClusterShards.forEach(dcClusterShard -> {
dcClusterShard.setSetinelId(randomlySelectedSentinelId);
try {
dcClusterShardService.updateDcClusterShard(dcClusterShard);
} catch (DalException e) {
throw new XpipeRuntimeException(e.getMessage());
}
});
}
}
use of com.ctrip.xpipe.exception.XpipeRuntimeException in project x-pipe by ctripcorp.
the class KinfoCommand method format.
protected ReplicationStoreMeta format(Object payload) {
ByteArrayOutputStreamPayload data = (ByteArrayOutputStreamPayload) payload;
String buff = new String(data.getBytes(), Codec.defaultCharset);
logger.info("[format]{}", buff);
ReplicationStoreMeta meta = null;
meta = JSON.parseObject(buff, ReplicationStoreMeta.class);
if (valid(meta)) {
return meta;
} else {
throw new XpipeRuntimeException("[format][wrong meta]" + meta);
}
}
use of com.ctrip.xpipe.exception.XpipeRuntimeException in project x-pipe by ctripcorp.
the class AdvancedDcMetaServiceTest method testRetry3TimesUntilSuccess.
@Test
public void testRetry3TimesUntilSuccess() throws Exception {
ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1);
service.setScheduled(scheduled).setFactory(new DefaultRetryCommandFactory(3, new RetryDelay(10), scheduled));
Command<String> command = service.retry3TimesUntilSuccess(new AbstractCommand<String>() {
private AtomicInteger counter = new AtomicInteger(0);
@Override
protected void doExecute() throws Exception {
int currentCount = counter.getAndIncrement();
logger.info(String.format("Run %d time", currentCount));
if (currentCount > 1) {
future().setSuccess("success");
} else {
throw new XpipeRuntimeException("test exception");
}
}
@Override
protected void doReset() {
}
@Override
public String getName() {
return "test-retry";
}
});
AtomicBoolean complete = new AtomicBoolean(false);
command.future().addListener(commandFuture -> {
Assert.assertEquals("success", commandFuture.getNow());
complete.getAndSet(true);
});
command.execute();
waitConditionUntilTimeOut(() -> complete.get());
}
Aggregations