Search in sources :

Example 11 with ComputeTaskSession

use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.

the class GridRoundRobinLoadBalancingSpiMultipleNodesSelfTest method testMultipleNodes.

/**
     * @throws Exception If test failed.
     */
@SuppressWarnings({ "ObjectEquality" })
public void testMultipleNodes() throws Exception {
    List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
    ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid());
    // Initialize.
    getSpi().getBalancedNode(ses, allNodes, new GridTestJob());
    List<UUID> orderedNodes = new ArrayList<>(getSpi().getNodeIds(ses));
    // Check the round-robin actually did circle.
    for (int i = 0; i < allNodes.size(); i++) {
        ClusterNode node = getSpi().getBalancedNode(ses, allNodes, new GridTestJob());
        assert orderedNodes.get(i) == node.id();
    }
    // Double-check.
    for (int i = 0; i < allNodes.size(); i++) {
        ClusterNode node = getSpi().getBalancedNode(ses, allNodes, new GridTestJob());
        assert orderedNodes.get(i) == node.id();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) GridTestJob(org.apache.ignite.GridTestJob) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 12 with ComputeTaskSession

use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.

the class GridRoundRobinLoadBalancingSpiNotPerTaskSelfTest method testMultipleTaskSessions.

/**
     * @throws Exception If test failed.
     */
public void testMultipleTaskSessions() throws Exception {
    ComputeTaskSession ses1 = new GridTestTaskSession(IgniteUuid.randomUuid());
    ComputeTaskSession ses2 = new GridTestTaskSession(IgniteUuid.randomUuid());
    List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
    List<UUID> orderedNodes = getSpi().getNodeIds(ses1);
    assertEquals("Balancer doesn't use all available nodes", orderedNodes.size(), allNodes.size());
    checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses1, ses2);
    getSpiContext().triggerEvent(new TaskEvent(null, null, EVT_TASK_FINISHED, ses1.getId(), null, null, false, null));
    getSpiContext().triggerEvent(new TaskEvent(null, null, EVT_TASK_FAILED, ses2.getId(), null, null, false, null));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) TaskEvent(org.apache.ignite.events.TaskEvent) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 13 with ComputeTaskSession

use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.

the class GridRoundRobinLoadBalancingSpiNotPerTaskSelfTest method testMultipleNodes.

/**
     * @throws Exception If test failed.
     */
public void testMultipleNodes() throws Exception {
    List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
    ComputeTaskSession ses = new GridTestTaskSession();
    List<UUID> orderedNodes = new ArrayList<>(getSpi().getNodeIds(ses));
    assertEquals("Balancer doesn't use all available nodes", orderedNodes.size(), allNodes.size());
    checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 14 with ComputeTaskSession

use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.

the class GridSingleSplitNewNodesTestTask method map.

/** {@inheritDoc} */
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Integer arg) {
    assert !subgrid.isEmpty() : "Subgrid cannot be empty.";
    Map<ComputeJobAdapter, ClusterNode> jobs = new HashMap<>(subgrid.size());
    taskSes.setAttribute("1st", "1");
    taskSes.setAttribute("2nd", "2");
    Collection<UUID> assigned = new ArrayList<>(subgrid.size());
    for (int i = 0; i < arg; i++) {
        ComputeJobAdapter job = new ComputeJobAdapter(1) {

            /** */
            @TaskSessionResource
            private ComputeTaskSession jobSes;

            /** {@inheritDoc} */
            @Override
            public Serializable execute() {
                assert jobSes != null;
                Integer arg = this.<Integer>argument(0);
                assert arg != null;
                return new GridSingleSplitNewNodesTestJobTarget().executeLoadTestJob(arg, jobSes);
            }
        };
        ClusterNode node = balancer.getBalancedNode(job, null);
        assert node != null;
        assigned.add(node.id());
        jobs.put(job, node);
    }
    taskSes.setAttribute("nodes", assigned);
    return jobs;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComputeJobAdapter(org.apache.ignite.compute.ComputeJobAdapter) UUID(java.util.UUID) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 15 with ComputeTaskSession

use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.

the class IgniteCacheLockPartitionOnAffinityRunTest method testReleasePartitionJobImplementMasterLeave.

/**
     * @throws Exception If failed.
     */
public void testReleasePartitionJobImplementMasterLeave() throws Exception {
    final int orgId = primaryKey(grid(0).cache(Organization.class.getSimpleName()));
    try {
        grid(1).compute().affinityRunAsync(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new RunnableWithMasterLeave() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public void onMasterNodeLeft(ComputeTaskSession ses) throws IgniteException {
            // No-op.
            }

            @Override
            public void run() {
                try {
                    checkPartitionsReservations((IgniteEx) ignite, orgId, 1);
                } catch (Exception e) {
                    e.printStackTrace();
                    fail("Unexpected exception");
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ignored) {
                // No-op.
                }
            }
        });
        stopGrid(1, true);
        Thread.sleep(3000);
        awaitPartitionMapExchange();
        checkPartitionsReservations(grid(0), orgId, 0);
    } finally {
        startGrid(1);
        awaitPartitionMapExchange();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Aggregations

ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)19 ClusterNode (org.apache.ignite.cluster.ClusterNode)12 UUID (java.util.UUID)10 GridTestTaskSession (org.apache.ignite.GridTestTaskSession)10 GridTestJob (org.apache.ignite.GridTestJob)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Ignite (org.apache.ignite.Ignite)5 IgniteException (org.apache.ignite.IgniteException)4 TaskEvent (org.apache.ignite.events.TaskEvent)4 GridTestNode (org.apache.ignite.testframework.GridTestNode)4 HashMap (java.util.HashMap)3 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ComputeJobAdapter (org.apache.ignite.compute.ComputeJobAdapter)2 ComputeJobSibling (org.apache.ignite.compute.ComputeJobSibling)2 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)2 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)2 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)2 TaskSessionResource (org.apache.ignite.resources.TaskSessionResource)2