Search in sources :

Example 21 with ClusterId

use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestContainer method setUp.

@Before
public void setUp() throws Exception {
    justThrowMe = null;
    throwMeInActivation = null;
    track(new SystemPropertyManager()).set("container-type", containerId);
    context = track(new ClassPathXmlApplicationContext(ctx));
    sessionFactory = new LocalClusterSessionFactory();
    final Node node = context.getBean(Node.class);
    manager = track(new NodeManager()).node(node).collaborator(track(sessionFactory.createSession())).start();
    statsCollector = manager.getClusterStatsCollector(new ClusterId("test-app", "test-cluster"));
    container = manager.getContainers().get(0);
    assertTrue(poll(manager, m -> m.isReady()));
}
Also used : Arrays(java.util.Arrays) Node(net.dempsy.config.Node) NodeManager(net.dempsy.NodeManager) ContainerTestMessage(net.dempsy.container.mocks.ContainerTestMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) MessageKey(net.dempsy.lifecycle.annotation.MessageKey) MessageHandler(net.dempsy.lifecycle.annotation.MessageHandler) Collection(java.util.Collection) Operation(net.dempsy.container.Container.Operation) Functional.uncheck(net.dempsy.util.Functional.uncheck) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Activation(net.dempsy.lifecycle.annotation.Activation) KeyExtractor(net.dempsy.lifecycle.annotation.utils.KeyExtractor) LockingContainer(net.dempsy.container.locking.LockingContainer) OutputMessage(net.dempsy.container.mocks.OutputMessage) Output(net.dempsy.lifecycle.annotation.Output) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Adaptor(net.dempsy.messages.Adaptor) AccessUtil.canReach(net.dempsy.AccessUtil.canReach) Start(net.dempsy.lifecycle.annotation.Start) Assert.assertFalse(org.junit.Assert.assertFalse) Evictable(net.dempsy.lifecycle.annotation.Evictable) MessageProcessor(net.dempsy.lifecycle.annotation.MessageProcessor) AccessUtil.getRouter(net.dempsy.AccessUtil.getRouter) Mp(net.dempsy.lifecycle.annotation.Mp) BlockingQueueReceiver(net.dempsy.transport.blockingqueue.BlockingQueueReceiver) NonLockingAltContainer(net.dempsy.container.altnonlocking.NonLockingAltContainer) MessageType(net.dempsy.lifecycle.annotation.MessageType) Dispatcher(net.dempsy.messages.Dispatcher) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) DempsyException(net.dempsy.DempsyException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BasicNodeStatsCollector(net.dempsy.monitoring.basic.BasicNodeStatsCollector) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(net.dempsy.config.ClusterId) Before(org.junit.Before) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Functional.recheck(net.dempsy.util.Functional.recheck) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) KeyedMessage(net.dempsy.messages.KeyedMessage) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Passivation(net.dempsy.lifecycle.annotation.Passivation) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterStatsCollector(net.dempsy.monitoring.ClusterStatsCollector) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) NodeManager(net.dempsy.NodeManager) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterId(net.dempsy.config.ClusterId) Node(net.dempsy.config.Node) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Before(org.junit.Before)

Example 22 with ClusterId

use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestSimpleRoutingStrategy method testInboundHappyPathRegister.

@Test
public void testInboundHappyPathRegister() throws Exception {
    final Manager<RoutingStrategy.Inbound> manager = new Manager<>(RoutingStrategy.Inbound.class);
    try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(SimpleRoutingStrategy.class.getPackage().getName())) {
        assertNotNull(ib);
        assertTrue(SimpleInboundSide.class.isAssignableFrom(ib.getClass()));
        ib.setContainerDetails(new ClusterId("test", "test"), new ContainerAddress(new DummyNodeAddress(), 0), (l, m) -> {
        });
        ib.start(infra);
        assertTrue(waitForReg(session));
    }
}
Also used : ClusterId(net.dempsy.config.ClusterId) RoutingStrategy(net.dempsy.router.RoutingStrategy) RoutingStrategyManager(net.dempsy.router.RoutingStrategyManager) Manager(net.dempsy.Manager) ContainerAddress(net.dempsy.router.RoutingStrategy.ContainerAddress) Test(org.junit.Test)

Example 23 with ClusterId

use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestSimpleRoutingStrategy method testInboundWithOutbound.

@Test
public void testInboundWithOutbound() throws Exception {
    final Manager<RoutingStrategy.Inbound> manager = new Manager<>(RoutingStrategy.Inbound.class);
    try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(SimpleRoutingStrategy.class.getPackage().getName())) {
        assertNotNull(ib);
        assertTrue(SimpleInboundSide.class.isAssignableFrom(ib.getClass()));
        final ClusterId cid = new ClusterId("test", "test");
        ib.setContainerDetails(cid, new ContainerAddress(new DummyNodeAddress("here"), 0), (l, m) -> {
        });
        ib.start(infra);
        assertTrue(waitForReg(session));
        try (final ClusterInfoSession ses2 = sessFact.createSession()) {
            try (final RoutingStrategyManager obman = chain(new RoutingStrategyManager(), o -> o.start(makeInfra(ses2, sched)));
                final RoutingStrategy.Factory obf = obman.getAssociatedInstance(SimpleRoutingStrategy.class.getPackage().getName())) {
                obf.start(makeInfra(ses2, sched));
                final RoutingStrategy.Router ob = obf.getStrategy(cid);
                final KeyedMessageWithType km = new KeyedMessageWithType(null, null, "");
                assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
                final ContainerAddress ca = ob.selectDestinationForMessage(km);
                assertNotNull(ca);
                assertEquals("here", ((DummyNodeAddress) ca.node).name);
                // now distupt the session
                session.close();
                // the destination should clear until a new in runs
                assertTrue(poll(o -> ob.selectDestinationForMessage(km) == null));
                try (ClusterInfoSession ses3 = sessFact.createSession();
                    RoutingStrategy.Inbound ib2 = manager.getAssociatedInstance(SimpleRoutingStrategy.class.getPackage().getName())) {
                    ib2.setContainerDetails(cid, ca, (l, m) -> {
                    });
                    ib2.start(makeInfra(ses3, sched));
                    assertTrue(poll(o -> ob.selectDestinationForMessage(km) != null));
                }
            }
        }
    }
}
Also used : ClusterInfoException(net.dempsy.cluster.ClusterInfoException) ClusterInfoSession(net.dempsy.cluster.ClusterInfoSession) ContainerAddress(net.dempsy.router.RoutingStrategy.ContainerAddress) Assert.assertNotNull(org.junit.Assert.assertNotNull) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) NodeAddress(net.dempsy.transport.NodeAddress) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) RoutingStrategyManager(net.dempsy.router.RoutingStrategyManager) AutoDisposeSingleThreadScheduler(net.dempsy.util.executor.AutoDisposeSingleThreadScheduler) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Infrastructure(net.dempsy.Infrastructure) RoutingStrategy(net.dempsy.router.RoutingStrategy) Functional.chain(net.dempsy.util.Functional.chain) After(org.junit.After) Manager(net.dempsy.Manager) TestInfrastructure(net.dempsy.util.TestInfrastructure) Assert.assertEquals(org.junit.Assert.assertEquals) ClusterId(net.dempsy.config.ClusterId) Before(org.junit.Before) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) RoutingStrategyManager(net.dempsy.router.RoutingStrategyManager) ClusterId(net.dempsy.config.ClusterId) RoutingStrategyManager(net.dempsy.router.RoutingStrategyManager) Manager(net.dempsy.Manager) ContainerAddress(net.dempsy.router.RoutingStrategy.ContainerAddress) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) RoutingStrategy(net.dempsy.router.RoutingStrategy) ClusterInfoSession(net.dempsy.cluster.ClusterInfoSession) Test(org.junit.Test)

Example 24 with ClusterId

use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestGroupRoutingStrategy method testInboundSimpleHappyPathRegister.

@Test
public void testInboundSimpleHappyPathRegister() throws Exception {
    final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
    final RoutingInboundManager manager = new RoutingInboundManager();
    try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":testInboundSimpleHappyPathRegister")) {
        final Utils<Object> msutils = new Utils<>(infra, "testInboundSimpleHappyPathRegister", new Object());
        assertNotNull(ib);
        assertTrue(ClusterGroupInbound.Proxy.class.isAssignableFrom(ib.getClass()));
        ib.setContainerDetails(new ClusterId("test", "test"), new ContainerAddress(new DummyNodeAddress("testInboundSimpleHappyPathRegister"), 0), (l, m) -> {
        });
        ib.start(infra);
        assertTrue(waitForShards(session, msutils, numShardsToExpect));
    }
}
Also used : RoutingInboundManager(net.dempsy.router.RoutingInboundManager) Utils(net.dempsy.router.shardutils.Utils) ClusterId(net.dempsy.config.ClusterId) RoutingStrategy(net.dempsy.router.RoutingStrategy) ContainerAddress(net.dempsy.router.RoutingStrategy.ContainerAddress) Test(org.junit.Test)

Example 25 with ClusterId

use of net.dempsy.config.ClusterId in project Dempsy by Dempsy.

the class TestGroupRoutingStrategy method testInboundResillience.

@Test
public void testInboundResillience() throws Exception {
    final int numShardsToExpect = Integer.parseInt(Utils.DEFAULT_TOTAL_SHARDS);
    final String groupName = "testInboundResillience";
    final Manager<RoutingStrategy.Inbound> manager = new RoutingInboundManager();
    try (final RoutingStrategy.Inbound ib = manager.getAssociatedInstance(ClusterGroupInbound.class.getPackage().getName() + ":" + groupName)) {
        final ClusterId clusterId = super.setTestName("testInboundResillience");
        final NodeAddress na = new DummyNodeAddress("theOnlyNode");
        final ContainerAddress ca = new ContainerAddress(na, 0);
        final GroupDetails gd = new GroupDetails(groupName, na);
        final Infrastructure infra = makeInfra(session, sched);
        final Utils<GroupDetails> msutils = new Utils<>(infra, groupName, gd);
        ib.setContainerDetails(clusterId, ca, (l, m) -> {
        });
        ib.start(infra);
        checkForShardDistribution(session, msutils, numShardsToExpect, 1);
        disruptor.accept(session);
        checkForShardDistribution(session, msutils, numShardsToExpect, 1);
    }
}
Also used : ClusterId(net.dempsy.config.ClusterId) ContainerAddress(net.dempsy.router.RoutingStrategy.ContainerAddress) RoutingInboundManager(net.dempsy.router.RoutingInboundManager) GroupDetails(net.dempsy.router.group.intern.GroupDetails) Utils(net.dempsy.router.shardutils.Utils) RoutingStrategy(net.dempsy.router.RoutingStrategy) TestInfrastructure(net.dempsy.util.TestInfrastructure) Infrastructure(net.dempsy.Infrastructure) NodeAddress(net.dempsy.transport.NodeAddress) Test(org.junit.Test)

Aggregations

ClusterId (net.dempsy.config.ClusterId)30 Test (org.junit.Test)24 ContainerAddress (net.dempsy.router.RoutingStrategy.ContainerAddress)16 List (java.util.List)15 ConditionPoll.poll (net.dempsy.utils.test.ConditionPoll.poll)15 Assert.assertEquals (org.junit.Assert.assertEquals)15 Assert.assertTrue (org.junit.Assert.assertTrue)15 Logger (org.slf4j.Logger)14 LoggerFactory (org.slf4j.LoggerFactory)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 ArrayList (java.util.ArrayList)12 RoutingStrategy (net.dempsy.router.RoutingStrategy)12 ClusterInfoSession (net.dempsy.cluster.ClusterInfoSession)11 NodeAddress (net.dempsy.transport.NodeAddress)11 Map (java.util.Map)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)9 Assert.assertNotNull (org.junit.Assert.assertNotNull)9 Before (org.junit.Before)9 Collections (java.util.Collections)8