Search in sources :

Example 6 with Manager

use of net.dempsy.Manager 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 7 with Manager

use of net.dempsy.Manager in project Dempsy by Dempsy.

the class TestManagedRoutingStrategy method testInboundSimpleHappyPathRegister.

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

Aggregations

Manager (net.dempsy.Manager)7 ClusterId (net.dempsy.config.ClusterId)7 RoutingStrategy (net.dempsy.router.RoutingStrategy)7 ContainerAddress (net.dempsy.router.RoutingStrategy.ContainerAddress)7 RoutingStrategyManager (net.dempsy.router.RoutingStrategyManager)7 Test (org.junit.Test)7 Infrastructure (net.dempsy.Infrastructure)4 Utils (net.dempsy.router.shardutils.Utils)4 TestInfrastructure (net.dempsy.util.TestInfrastructure)4 ClusterInfoException (net.dempsy.cluster.ClusterInfoException)3 ClusterInfoSession (net.dempsy.cluster.ClusterInfoSession)3 KeyedMessageWithType (net.dempsy.messages.KeyedMessageWithType)3 NodeAddress (net.dempsy.transport.NodeAddress)3 Functional.chain (net.dempsy.util.Functional.chain)3 ConditionPoll.poll (net.dempsy.utils.test.ConditionPoll.poll)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2