Search in sources :

Example 1 with XpipeRuntimeException

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());
}
Also used : XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) Test(org.junit.Test)

Example 2 with XpipeRuntimeException

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);
        }
    }
}
Also used : XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) BeansException(org.springframework.beans.BeansException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent)

Example 3 with XpipeRuntimeException

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());
            }
        });
    }
}
Also used : DalException(org.unidal.dal.jdbc.DalException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

Example 4 with XpipeRuntimeException

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);
    }
}
Also used : ReplicationStoreMeta(com.ctrip.xpipe.redis.core.store.ReplicationStoreMeta) ByteArrayOutputStreamPayload(com.ctrip.xpipe.payload.ByteArrayOutputStreamPayload) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException)

Example 5 with XpipeRuntimeException

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DefaultRetryCommandFactory(com.ctrip.xpipe.command.DefaultRetryCommandFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryDelay(com.ctrip.xpipe.retry.RetryDelay) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) IOException(java.io.IOException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Aggregations

XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)5 Test (org.junit.Test)2 DefaultRetryCommandFactory (com.ctrip.xpipe.command.DefaultRetryCommandFactory)1 ByteArrayOutputStreamPayload (com.ctrip.xpipe.payload.ByteArrayOutputStreamPayload)1 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1 ReplicationStoreMeta (com.ctrip.xpipe.redis.core.store.ReplicationStoreMeta)1 RetryDelay (com.ctrip.xpipe.retry.RetryDelay)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1 IOException (java.io.IOException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BeansException (org.springframework.beans.BeansException)1 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)1 ContextRefreshedEvent (org.springframework.context.event.ContextRefreshedEvent)1 DalException (org.unidal.dal.jdbc.DalException)1