|
20 | 20 | import java.lang.reflect.Field; |
21 | 21 | import java.sql.Connection; |
22 | 22 | import java.util.Arrays; |
23 | | -import java.util.Collections; |
24 | 23 | import java.util.HashMap; |
25 | 24 | import java.util.HashSet; |
26 | 25 | import java.util.Iterator; |
|
35 | 34 | import java.util.concurrent.atomic.AtomicInteger; |
36 | 35 | import java.util.concurrent.atomic.AtomicLong; |
37 | 36 | import java.util.function.Consumer; |
| 37 | +import java.util.function.Function; |
| 38 | +import java.util.stream.Collectors; |
38 | 39 | import javax.cache.Cache; |
39 | 40 | import javax.cache.expiry.CreatedExpiryPolicy; |
40 | 41 | import javax.cache.expiry.Duration; |
|
92 | 93 | import org.apache.ignite.internal.processors.metric.impl.PeriodicHistogramMetricImpl; |
93 | 94 | import org.apache.ignite.internal.processors.odbc.jdbc.JdbcConnectionContext; |
94 | 95 | import org.apache.ignite.internal.processors.service.DummyService; |
| 96 | +import org.apache.ignite.internal.processors.task.GridInternal; |
95 | 97 | import org.apache.ignite.internal.util.GridTestClockTimer; |
96 | 98 | import org.apache.ignite.internal.util.StripedExecutor; |
97 | 99 | import org.apache.ignite.internal.util.typedef.F; |
|
103 | 105 | import org.apache.ignite.lang.IgniteClosure; |
104 | 106 | import org.apache.ignite.lang.IgnitePredicate; |
105 | 107 | import org.apache.ignite.lang.IgniteRunnable; |
| 108 | +import org.apache.ignite.lang.IgniteUuid; |
106 | 109 | import org.apache.ignite.services.ServiceConfiguration; |
107 | 110 | import org.apache.ignite.spi.systemview.view.BaselineNodeAttributeView; |
108 | 111 | import org.apache.ignite.spi.systemview.view.BaselineNodeView; |
|
114 | 117 | import org.apache.ignite.spi.systemview.view.ClientConnectionAttributeView; |
115 | 118 | import org.apache.ignite.spi.systemview.view.ClientConnectionView; |
116 | 119 | import org.apache.ignite.spi.systemview.view.ClusterNodeView; |
| 120 | +import org.apache.ignite.spi.systemview.view.ComputeJobView; |
117 | 121 | import org.apache.ignite.spi.systemview.view.ComputeTaskView; |
118 | 122 | import org.apache.ignite.spi.systemview.view.ConfigurationView; |
119 | 123 | import org.apache.ignite.spi.systemview.view.ContinuousQueryView; |
|
180 | 184 | import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.SETS_VIEW; |
181 | 185 | import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.STAMPED_VIEW; |
182 | 186 | import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.VOLATILE_DATA_REGION_NAME; |
| 187 | +import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW; |
183 | 188 | import static org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl.DISTRIBUTED_METASTORE_VIEW; |
184 | 189 | import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName; |
185 | 190 | import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLI_CONN_ATTR_VIEW; |
@@ -209,6 +214,12 @@ public class SystemViewSelfTest extends GridCommonAbstractTest { |
209 | 214 | /** */ |
210 | 215 | public static final String TEST_TRANSFORMER = "TestTransformer"; |
211 | 216 |
|
| 217 | + /** */ |
| 218 | + private static CountDownLatch jobStartedLatch; |
| 219 | + |
| 220 | + /** */ |
| 221 | + private static CountDownLatch releaseJobLatch; |
| 222 | + |
212 | 223 | /** {@inheritDoc} */ |
213 | 224 | @Override protected void beforeTestsStarted() throws Exception { |
214 | 225 | super.beforeTestsStarted(); |
@@ -598,63 +609,80 @@ public void testComputeAffinityCall() throws Exception { |
598 | 609 | /** */ |
599 | 610 | @Test |
600 | 611 | public void testComputeTask() throws Exception { |
601 | | - CyclicBarrier barrier = new CyclicBarrier(2); |
| 612 | + doTestComputeTask(false); |
| 613 | + } |
602 | 614 |
|
603 | | - try (IgniteEx g1 = startGrid(0)) { |
604 | | - SystemView<ComputeTaskView> tasks = g1.context().systemView().view(TASKS_VIEW); |
| 615 | + /** */ |
| 616 | + @Test |
| 617 | + public void testInternalComputeTask() throws Exception { |
| 618 | + doTestComputeTask(true); |
| 619 | + } |
| 620 | + |
| 621 | + /** */ |
| 622 | + private void doTestComputeTask(boolean internal) throws Exception { |
| 623 | + int gridCnt = 3; |
605 | 624 |
|
| 625 | + IgniteEx g1 = startGrids(gridCnt); |
| 626 | + |
| 627 | + try { |
606 | 628 | IgniteCache<Integer, Integer> cache = g1.createCache("test-cache"); |
607 | 629 |
|
608 | 630 | cache.put(1, 1); |
609 | 631 |
|
610 | | - g1.compute().executeAsync(new ComputeTask<Object, Object>() { |
611 | | - @Override public @NotNull Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, |
612 | | - @Nullable Object arg) throws IgniteException { |
613 | | - return Collections.singletonMap(new ComputeJob() { |
614 | | - @Override public void cancel() { |
615 | | - // No-op. |
616 | | - } |
| 632 | + for (int i = 0; i < gridCnt; i++) { |
| 633 | + IgniteEx grid = grid(i); |
617 | 634 |
|
618 | | - @Override public Object execute() throws IgniteException { |
619 | | - return 1; |
620 | | - } |
621 | | - }, subgrid.get(0)); |
622 | | - } |
| 635 | + SystemView<ComputeTaskView> tasks = grid.context().systemView().view(TASKS_VIEW); |
623 | 636 |
|
624 | | - @Override public ComputeJobResultPolicy result(ComputeJobResult res, |
625 | | - List<ComputeJobResult> rcvd) throws IgniteException { |
626 | | - try { |
627 | | - barrier.await(); |
628 | | - barrier.await(); |
629 | | - } |
630 | | - catch (InterruptedException | BrokenBarrierException e) { |
631 | | - throw new RuntimeException(e); |
632 | | - } |
| 637 | + jobStartedLatch = new CountDownLatch(3); |
| 638 | + releaseJobLatch = new CountDownLatch(1); |
633 | 639 |
|
634 | | - return null; |
635 | | - } |
| 640 | + IgniteInternalFuture<Object> fut |
| 641 | + = runAsync(() -> grid.compute().execute(internal ? new InternalTask() : new UserTask(), 1)); |
| 642 | + |
| 643 | + assertTrue(jobStartedLatch.await(30_000, TimeUnit.MILLISECONDS)); |
| 644 | + |
| 645 | + try { |
| 646 | + assertEquals(1, tasks.size()); |
| 647 | + |
| 648 | + ComputeTaskView t = tasks.iterator().next(); |
636 | 649 |
|
637 | | - @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException { |
638 | | - return 1; |
| 650 | + assertEquals("Expecting to see " + (internal ? "internal" : "user") + " task", internal, t.internal()); |
| 651 | + assertNull(t.affinityCacheName()); |
| 652 | + assertEquals(-1, t.affinityPartitionId()); |
| 653 | + assertTrue(t.taskClassName().startsWith(getClass().getName())); |
| 654 | + assertTrue(t.taskName().startsWith(getClass().getName())); |
| 655 | + assertEquals(grid.localNode().id(), t.taskNodeId()); |
| 656 | + assertEquals("0", t.userVersion()); |
| 657 | + |
| 658 | + checkJobs(gridCnt, internal, t.sessionId()); |
| 659 | + } |
| 660 | + finally { |
| 661 | + releaseJobLatch.countDown(); |
639 | 662 | } |
640 | | - }, 1); |
641 | 663 |
|
642 | | - barrier.await(); |
| 664 | + fut.get(getTestTimeout(), TimeUnit.MILLISECONDS); |
| 665 | + } |
| 666 | + } |
| 667 | + finally { |
| 668 | + stopAllGrids(); |
| 669 | + } |
| 670 | + } |
643 | 671 |
|
644 | | - assertEquals(1, tasks.size()); |
| 672 | + /** */ |
| 673 | + private void checkJobs(int gridCnt, boolean internal, IgniteUuid sesId) { |
| 674 | + for (int i = 0; i < gridCnt; i++) { |
| 675 | + SystemView<ComputeJobView> jobs = grid(i).context().systemView().view(JOBS_VIEW); |
645 | 676 |
|
646 | | - ComputeTaskView t = tasks.iterator().next(); |
| 677 | + assertTrue("Expecting to see " + (internal ? "internal" : "user") + " job", jobs.size() > 0); |
647 | 678 |
|
648 | | - assertFalse(t.internal()); |
649 | | - assertNull(t.affinityCacheName()); |
650 | | - assertEquals(-1, t.affinityPartitionId()); |
651 | | - assertTrue(t.taskClassName().startsWith(getClass().getName())); |
652 | | - assertTrue(t.taskName().startsWith(getClass().getName())); |
653 | | - assertEquals(g1.localNode().id(), t.taskNodeId()); |
654 | | - assertEquals("0", t.userVersion()); |
| 679 | + ComputeJobView job = jobs.iterator().next(); |
655 | 680 |
|
656 | | - barrier.await(); |
| 681 | + assertEquals(sesId, job.sessionId()); |
| 682 | + assertEquals("Expecting to see " + (internal ? "internal" : "user") + " job", internal, job.isInternal()); |
657 | 683 | } |
| 684 | + |
| 685 | + releaseJobLatch.countDown(); |
658 | 686 | } |
659 | 687 |
|
660 | 688 | /** */ |
@@ -2592,4 +2620,53 @@ public TestRunnable(CountDownLatch latch, int idx) { |
2592 | 2620 | return getClass().getSimpleName() + idx; |
2593 | 2621 | } |
2594 | 2622 | } |
| 2623 | + |
| 2624 | + /** */ |
| 2625 | + private static class UserTask implements ComputeTask<Object, Object> { |
| 2626 | + /** {@inheritDoc} */ |
| 2627 | + @Override public @NotNull Map<? extends ComputeJob, ClusterNode> map( |
| 2628 | + List<ClusterNode> subgrid, |
| 2629 | + @Nullable Object arg |
| 2630 | + ) throws IgniteException { |
| 2631 | + return subgrid.stream().collect(Collectors.toMap(k -> new UserJob(), Function.identity())); |
| 2632 | + } |
| 2633 | + |
| 2634 | + /** {@inheritDoc} */ |
| 2635 | + @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException { |
| 2636 | + return ComputeJobResultPolicy.WAIT; |
| 2637 | + } |
| 2638 | + |
| 2639 | + /** {@inheritDoc} */ |
| 2640 | + @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException { |
| 2641 | + return 1; |
| 2642 | + } |
| 2643 | + |
| 2644 | + /** */ |
| 2645 | + private static class UserJob implements ComputeJob { |
| 2646 | + /** {@inheritDoc} */ |
| 2647 | + @Override public void cancel() { |
| 2648 | + // No-op. |
| 2649 | + } |
| 2650 | + |
| 2651 | + /** {@inheritDoc} */ |
| 2652 | + @Override public Object execute() throws IgniteException { |
| 2653 | + jobStartedLatch.countDown(); |
| 2654 | + |
| 2655 | + try { |
| 2656 | + assertTrue(releaseJobLatch.await(30_000, TimeUnit.MILLISECONDS)); |
| 2657 | + } |
| 2658 | + catch (InterruptedException e) { |
| 2659 | + throw new RuntimeException(e); |
| 2660 | + } |
| 2661 | + |
| 2662 | + return 1; |
| 2663 | + } |
| 2664 | + } |
| 2665 | + } |
| 2666 | + |
| 2667 | + /** */ |
| 2668 | + @GridInternal |
| 2669 | + public static class InternalTask extends UserTask { |
| 2670 | + // No-op. |
| 2671 | + } |
2595 | 2672 | } |
0 commit comments