Search in sources :

Example 16 with GridTestTaskSession

use of org.apache.ignite.GridTestTaskSession in project ignite by apache.

the class GridAlwaysFailoverSpiSelfTest method testSingleNode.

/**
     * @throws Exception If failed.
     */
public void testSingleNode() throws Exception {
    AlwaysFailoverSpi spi = getSpi();
    List<ClusterNode> nodes = new ArrayList<>();
    ClusterNode node = new GridTestNode(UUID.randomUUID());
    nodes.add(node);
    node = spi.failover(new GridFailoverTestContext(new GridTestTaskSession(), new GridTestJobResult(node)), nodes);
    assert node == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) ArrayList(java.util.ArrayList) GridTestJobResult(org.apache.ignite.GridTestJobResult) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridFailoverTestContext(org.apache.ignite.spi.failover.GridFailoverTestContext)

Example 17 with GridTestTaskSession

use of org.apache.ignite.GridTestTaskSession in project ignite by apache.

the class GridJobStealingFailoverSpiOneNodeSelfTest method testNoFailover.

/**
     * @throws Exception If test failed.
     */
public void testNoFailover() throws Exception {
    ClusterNode rmt = getSpiContext().remoteNodes().iterator().next();
    GridTestJobResult failed = new GridTestJobResult(rmt);
    ClusterNode other = getSpi().failover(new GridFailoverTestContext(new GridTestTaskSession(), failed), Collections.singletonList(getSpiContext().remoteNodes().iterator().next()));
    assert other == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) GridTestJobResult(org.apache.ignite.GridTestJobResult) GridFailoverTestContext(org.apache.ignite.spi.failover.GridFailoverTestContext)

Example 18 with GridTestTaskSession

use of org.apache.ignite.GridTestTaskSession in project ignite by apache.

the class GridWeightedRandomLoadBalancingSpiSelfTest method testMultipleNodes.

/**
     * @throws Exception If failed.
     */
public void testMultipleNodes() throws Exception {
    List<ClusterNode> nodes = new ArrayList<>();
    for (int i = 0; i < 10; i++) nodes.add(new GridTestNode(UUID.randomUUID()));
    // Seal it.
    nodes = Collections.unmodifiableList(nodes);
    ClusterNode node = getSpi().getBalancedNode(new GridTestTaskSession(), nodes, new GridTestJob());
    assert node != null;
    assert nodes.contains(node);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) ArrayList(java.util.ArrayList) GridTestJob(org.apache.ignite.GridTestJob) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 19 with GridTestTaskSession

use of org.apache.ignite.GridTestTaskSession in project ignite by apache.

the class GridRoundRobinLoadBalancingNotPerTaskMultithreadedSelfTest method testMultipleTaskSessionsMultithreaded.

/**
     *
     * @throws Exception If failed.
     */
public void testMultipleTaskSessionsMultithreaded() throws Exception {
    final RoundRobinLoadBalancingSpi spi = getSpi();
    final List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
    GridTestUtils.runMultiThreaded(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid());
            Map<UUID, AtomicInteger> nodeCnts = new HashMap<>();
            for (int i = 1; i <= ITER_CNT; i++) {
                ClusterNode node = spi.getBalancedNode(ses, allNodes, new GridTestJob());
                if (!nodeCnts.containsKey(node.id()))
                    nodeCnts.put(node.id(), new AtomicInteger(1));
                else
                    nodeCnts.get(node.id()).incrementAndGet();
            }
            int predictCnt = ITER_CNT / allNodes.size();
            // Consider +-20% is permissible spread for single node measure.
            int floor = (int) (predictCnt * 0.8);
            double avgSpread = 0;
            for (ClusterNode n : allNodes) {
                int curCnt = nodeCnts.get(n.id()).intValue();
                avgSpread += Math.abs(predictCnt - curCnt);
                String msg = "Node stats [id=" + n.id() + ", cnt=" + curCnt + ", floor=" + floor + ", predictCnt=" + predictCnt + ']';
                info(msg);
                assertTrue(msg, curCnt >= floor);
            }
            avgSpread /= allNodes.size();
            avgSpread = 100.0 * avgSpread / predictCnt;
            info("Average spread for " + allNodes.size() + " nodes is " + avgSpread + " percents");
            // Consider +-10% is permissible average spread for all nodes.
            assertTrue("Average spread is too big: " + avgSpread, avgSpread <= 10);
            return null;
        }
    }, THREAD_CNT, "balancer-test-worker");
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) GridTestJob(org.apache.ignite.GridTestJob) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 20 with GridTestTaskSession

use of org.apache.ignite.GridTestTaskSession in project ignite by apache.

the class GridRoundRobinLoadBalancingSpiLocalNodeSelfTest method testLocalNode.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings({ "ObjectEquality" })
public void testLocalNode() throws Exception {
    assert getDiscoverySpi().getRemoteNodes().isEmpty();
    ClusterNode locNode = getDiscoverySpi().getLocalNode();
    ClusterNode node = getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), Collections.singletonList(locNode), new GridTestJob());
    assert node == locNode;
    // Double check.
    node = getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), Collections.singletonList(locNode), new GridTestJob());
    assert node == locNode;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) GridTestJob(org.apache.ignite.GridTestJob)

Aggregations

GridTestTaskSession (org.apache.ignite.GridTestTaskSession)29 ClusterNode (org.apache.ignite.cluster.ClusterNode)29 GridTestJob (org.apache.ignite.GridTestJob)14 GridTestNode (org.apache.ignite.testframework.GridTestNode)14 GridTestJobResult (org.apache.ignite.GridTestJobResult)13 GridFailoverTestContext (org.apache.ignite.spi.failover.GridFailoverTestContext)13 ArrayList (java.util.ArrayList)12 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)10 List (java.util.List)7 UUID (java.util.UUID)5 ComputeJobResult (org.apache.ignite.compute.ComputeJobResult)2 TaskEvent (org.apache.ignite.events.TaskEvent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteException (org.apache.ignite.IgniteException)1