Search in sources :

Example 1 with ClusterInfoSessionFactory

use of net.dempsy.cluster.ClusterInfoSessionFactory in project Dempsy by Dempsy.

the class DempsyBaseTest method runCombos.

protected void runCombos(final String testName, final ComboFilter filter, final String[][] ctxs, final String[][][] perNodeProps, final TestToRun test) throws Exception {
    if (filter != null && !filter.filter(routerId, containerId, sessionType, transportType, serializerType))
        return;
    final long comboSequence = runComboSequence.getAndIncrement();
    currentAppName = testName + "-" + comboSequence;
    LOGGER.info("=====================================================================================");
    LOGGER.info("======== Running (" + comboSequence + ") " + testName + " with " + routerId + ", " + containerId + ", " + sessionType + ", " + threadingModelDescription + ", " + transportType + "/" + serializerType);
    try (final ServiceTracker tr = new ServiceTracker()) {
        currentlyTracking = tr;
        tr.track(new SystemPropertyManager()).set("routing-strategy", ROUTER_ID_PREFIX + routerId).set("container-type", CONTAINER_ID_PREFIX + containerId).set("test-name", currentAppName).setIfAbsent("total_shards", Integer.toString(NUM_MICROSHARDS));
        // instantiate session factory
        final ClusterInfoSessionFactory sessFact = tr.track(new ClassPathXmlApplicationContext(COLLAB_CTX_PREFIX + sessionType + COLLAB_CTX_SUFFIX)).getBean(ClusterInfoSessionFactory.class);
        currentSessionFactory = sessFact;
        final List<NodeManagerWithContext> reverseCpCtxs = reverseRange(0, ctxs.length).mapToObj(i -> {
            try (final SystemPropertyManager p2 = new SystemPropertyManager()) {
                if (perNodeProps != null && perNodeProps[i] != null) {
                    for (final String[] kv : perNodeProps[i]) {
                        if (kv != null) {
                            if (kv.length != 2)
                                throw new IllegalArgumentException("Invalid KV Pair passed for per-node property");
                            p2.set(kv[0], kv[1]);
                        }
                    }
                }
                final NodeManagerWithContext ret = makeNode(ctxs[i]);
                // we can only do this level of polling when the min_nodes isn't set or is set to 1.
                final String minNodesProp = System.getProperty("min_nodes");
                if (minNodesProp != null && Integer.parseInt(minNodesProp) == 1)
                    assertTrue(qpoll(ret, o -> o.manager.isReady()));
                return ret;
            }
        }).collect(Collectors.toList());
        final List<NodeManagerWithContext> cpCtxs = reverseRange(0, reverseCpCtxs.size()).mapToObj(i -> reverseCpCtxs.get(i)).collect(Collectors.toList());
        for (final NodeManagerWithContext n : cpCtxs) assertTrue(poll(o -> n.manager.isReady()));
        test.test(new Nodes(cpCtxs, sessFact));
        currentlyTracking = null;
    } finally {
        LocalClusterSessionFactory.completeReset();
        BlockingQueueAddress.completeReset();
        ClassTracker.dumpResults();
    }
    test.postShutdown();
    System.gc();
    System.gc();
    System.gc();
    System.gc();
    System.gc();
    System.gc();
    for (final long endTime = System.currentTimeMillis() + TEN_SECONDS; Thread.activeCount() > 3; ) {
        ignore(() -> Thread.sleep(10));
        if (Thread.activeCount() > 3 && (System.currentTimeMillis() > endTime)) {
            LOGGER.error("There appears to be an incomplete shutdown! There are {} threads running after stop.", Thread.activeCount());
            break;
        }
    }
}
Also used : BlockingQueueAddress(net.dempsy.transport.blockingqueue.BlockingQueueAddress) Arrays(java.util.Arrays) Node(net.dempsy.config.Node) DefaultThreadingModel(net.dempsy.threading.DefaultThreadingModel) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Functional.ignore(net.dempsy.util.Functional.ignore) OrderedPerContainerThreadingModel(net.dempsy.threading.OrderedPerContainerThreadingModel) ThreadingModel(net.dempsy.threading.ThreadingModel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Parameterized(org.junit.runners.Parameterized) LocalClusterSessionFactory(net.dempsy.cluster.local.LocalClusterSessionFactory) Cluster(net.dempsy.config.Cluster) Logger(org.slf4j.Logger) ClassTracker(net.dempsy.serialization.util.ClassTracker) ClusterInfoSessionFactory(net.dempsy.cluster.ClusterInfoSessionFactory) Collection(java.util.Collection) Functional.uncheck(net.dempsy.util.Functional.uncheck) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Assert.assertTrue(org.junit.Assert.assertTrue) Collectors(java.util.stream.Collectors) ConditionPoll.qpoll(net.dempsy.utils.test.ConditionPoll.qpoll) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) Functional.reverseRange(net.dempsy.util.Functional.reverseRange) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) ClusterInfoSessionFactory(net.dempsy.cluster.ClusterInfoSessionFactory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ClusterInfoSessionFactory (net.dempsy.cluster.ClusterInfoSessionFactory)1 LocalClusterSessionFactory (net.dempsy.cluster.local.LocalClusterSessionFactory)1 Cluster (net.dempsy.config.Cluster)1 Node (net.dempsy.config.Node)1 ClassTracker (net.dempsy.serialization.util.ClassTracker)1 DefaultThreadingModel (net.dempsy.threading.DefaultThreadingModel)1 OrderedPerContainerThreadingModel (net.dempsy.threading.OrderedPerContainerThreadingModel)1 ThreadingModel (net.dempsy.threading.ThreadingModel)1 BlockingQueueAddress (net.dempsy.transport.blockingqueue.BlockingQueueAddress)1 Functional.ignore (net.dempsy.util.Functional.ignore)1 Functional.reverseRange (net.dempsy.util.Functional.reverseRange)1 Functional.uncheck (net.dempsy.util.Functional.uncheck)1 SystemPropertyManager (net.dempsy.util.SystemPropertyManager)1