コード例 #1
0
  /** @throws Exception If failed. */
  @SuppressWarnings({"ObjectEquality"})
  public void testDifferentTasks() throws Exception {
    Grid grid1 = null;
    Grid grid2 = null;

    try {
      grid1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext()));
      grid2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext()));

      // Execute different tasks.
      grid1.compute().execute(SharedResourceTask1.class, null).get();
      grid1.compute().execute(SharedResourceTask2.class, null).get();

      // In ISOLATED_CLASSLOADER mode tasks should have the class
      // loaders because they have the same CL locally and thus the same
      // resources.
      // So 1 resource locally and 1 remotely
      assert task1Rsrc1 == task2Rsrc1;
      assert task1Rsrc2 == task2Rsrc2;
      assert task1Rsrc3 == task2Rsrc3;
      assert task1Rsrc4 == task2Rsrc4;

      checkUsageCount(createClss, UserResource1.class, 4);
      checkUsageCount(createClss, UserResource2.class, 4);

      checkUsageCount(deployClss, UserResource1.class, 4);
      checkUsageCount(deployClss, UserResource2.class, 4);
    } finally {
      GridTestUtils.close(grid1, log());
      GridTestUtils.close(grid2, log());
    }

    checkUsageCount(undeployClss, UserResource1.class, 4);
    checkUsageCount(undeployClss, UserResource2.class, 4);
  }
コード例 #2
0
  /** @throws Exception If failed. */
  @SuppressWarnings({"ObjectEquality"})
  public void testUndeployedTask() throws Exception {
    Grid grid1 = null;
    Grid grid2 = null;

    try {
      grid1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext()));
      grid2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext()));

      // Execute tasks.
      grid1.compute().execute(SharedResourceTask1.class, null).get();
      grid1.compute().execute(SharedResourceTask2.class, null).get();

      grid1.compute().undeployTask(SharedResourceTask1.class.getName());

      // Wait until resources get undeployed remotely
      // because undeploy is asynchronous apply.
      Thread.sleep(3000);

      // 1 local and 1 remote resource instances
      checkUsageCount(createClss, UserResource1.class, 4);
      checkUsageCount(deployClss, UserResource1.class, 4);
      checkUsageCount(createClss, UserResource2.class, 4);
      checkUsageCount(deployClss, UserResource2.class, 4);
      checkUsageCount(undeployClss, UserResource1.class, 4);
      checkUsageCount(undeployClss, UserResource2.class, 4);

      grid1.compute().undeployTask(SharedResourceTask2.class.getName());

      // Wait until resources get undeployed remotely
      // because undeploy is asynchronous apply.
      Thread.sleep(3000);

      // We undeployed last task for this class loader and resources.
      // All resources should be undeployed.
      checkUsageCount(undeployClss, UserResource1.class, 4);
      checkUsageCount(undeployClss, UserResource2.class, 4);

      // Execute the same tasks.
      grid1.compute().execute(SharedResourceTask1.class, null).get();
      grid1.compute().execute(SharedResourceTask2.class, null).get();

      // 2 new resources.
      checkUsageCount(createClss, UserResource1.class, 8);
      checkUsageCount(deployClss, UserResource1.class, 8);
      checkUsageCount(createClss, UserResource2.class, 8);
      checkUsageCount(deployClss, UserResource2.class, 8);
    } finally {
      GridTestUtils.close(grid1, log());
      GridTestUtils.close(grid2, log());
    }

    checkUsageCount(undeployClss, UserResource1.class, 8);
    checkUsageCount(undeployClss, UserResource2.class, 8);
  }
コード例 #3
0
  /** {@inheritDoc} */
  @Override
  protected GridConfiguration getConfiguration(String gridName) throws Exception {
    GridConfiguration c = super.getConfiguration(gridName);

    c.setLocalHost(HOST);

    assert c.getClientConnectionConfiguration() == null;

    GridClientConnectionConfiguration clientCfg = new GridClientConnectionConfiguration();

    clientCfg.setRestTcpPort(REST_TCP_PORT_BASE);

    GridSslContextFactory sslCtxFactory = sslContextFactory();

    if (sslCtxFactory != null) {
      clientCfg.setRestTcpSslEnabled(true);
      clientCfg.setRestTcpSslContextFactory(sslCtxFactory);
    }

    c.setClientConnectionConfiguration(clientCfg);

    GridTcpDiscoverySpi disco = new GridTcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    c.setDiscoverySpi(disco);

    TestCommunicationSpi spi = new TestCommunicationSpi();

    spi.setLocalPort(GridTestUtils.getNextCommPort(getClass()));

    c.setCommunicationSpi(spi);

    c.setCacheConfiguration(
        cacheConfiguration(null),
        cacheConfiguration(PARTITIONED_CACHE_NAME),
        cacheConfiguration(REPLICATED_CACHE_NAME),
        cacheConfiguration(REPLICATED_ASYNC_CACHE_NAME));

    ThreadPoolExecutor exec =
        new ThreadPoolExecutor(40, 40, 0, MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    exec.prestartAllCoreThreads();

    c.setExecutorService(exec);

    c.setExecutorServiceShutdown(true);

    ThreadPoolExecutor sysExec =
        new ThreadPoolExecutor(40, 40, 0, MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    sysExec.prestartAllCoreThreads();

    c.setSystemExecutorService(sysExec);

    c.setSystemExecutorServiceShutdown(true);

    return c;
  }
コード例 #4
0
  /** @throws Exception If failed. */
  public void testSameTaskFromTwoNodesLeft() throws Exception {
    Grid grid1 = null;
    Grid grid2 = null;
    Grid grid3 = null;

    try {
      grid1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext()));
      grid2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext()));
      grid3 = startGrid(3, new GridSpringResourceContextImpl(new GenericApplicationContext()));

      grid1.compute().execute(SharedResourceTask1.class, null).get();
      grid2.compute().execute(SharedResourceTask1.class, null).get();

      checkUsageCount(createClss, UserResource1.class, 6);
      checkUsageCount(deployClss, UserResource1.class, 6);
      checkUsageCount(createClss, UserResource2.class, 6);
      checkUsageCount(deployClss, UserResource2.class, 6);

      checkUsageCount(undeployClss, UserResource1.class, 0);
      checkUsageCount(undeployClss, UserResource2.class, 0);

      GridTestUtils.close(grid1, log());

      // Wait until other nodes get notified
      // this grid1 left.
      Thread.sleep(1000);

      // Undeployment happened only on Grid1.
      checkUsageCount(undeployClss, UserResource1.class, 2);
      checkUsageCount(undeployClss, UserResource2.class, 2);

      GridTestUtils.close(grid2, log());

      // Wait until resources get undeployed remotely
      // because undeploy is asynchronous apply.
      Thread.sleep(1000);

      // Grid1 and Grid2
      checkUsageCount(undeployClss, UserResource1.class, 4);
      checkUsageCount(undeployClss, UserResource2.class, 4);
    } finally {
      GridTestUtils.close(grid1, log());
      GridTestUtils.close(grid2, log());
      GridTestUtils.close(grid3, log());
    }
  }
コード例 #5
0
  /** @throws Exception If failed. */
  public void testSameTaskFromTwoNodesUndeploy() throws Exception {
    Grid grid1 = null;
    Grid grid2 = null;
    Grid grid3 = null;

    try {
      grid1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext()));
      grid2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext()));
      grid3 = startGrid(3, new GridSpringResourceContextImpl(new GenericApplicationContext()));

      grid1.compute().execute(SharedResourceTask1.class, null).get();
      grid2.compute().execute(SharedResourceTask1.class, null).get();

      checkUsageCount(createClss, UserResource1.class, 6);
      checkUsageCount(deployClss, UserResource1.class, 6);
      checkUsageCount(createClss, UserResource2.class, 6);
      checkUsageCount(deployClss, UserResource2.class, 6);

      checkUsageCount(undeployClss, UserResource1.class, 0);
      checkUsageCount(undeployClss, UserResource2.class, 0);

      grid1.compute().undeployTask(SharedResourceTask1.class.getName());

      // Wait until resources get undeployed remotely
      // because undeploy is asynchronous apply.
      Thread.sleep(3000);

      checkUsageCount(undeployClss, UserResource1.class, 6);
      checkUsageCount(undeployClss, UserResource2.class, 6);

      grid2.compute().undeployTask(SharedResourceTask1.class.getName());

      // Wait until resources get undeployed remotely
      // because undeploy is asynchronous apply.
      Thread.sleep(3000);

      // All Tasks from originating nodes were undeployed. All resources should be cleaned up.
      checkUsageCount(undeployClss, UserResource1.class, 6);
      checkUsageCount(undeployClss, UserResource2.class, 6);
    } finally {
      GridTestUtils.close(grid1, log());
      GridTestUtils.close(grid2, log());
      GridTestUtils.close(grid3, log());
    }
  }
コード例 #6
0
  /** @throws Exception If failed. */
  @SuppressWarnings("unchecked")
  public void testRedeployedTask() throws Exception {
    Grid grid = startGrid(0, new GridSpringResourceContextImpl(new GenericApplicationContext()));

    try {
      // Execute same task with different class loaders. Second execution should redeploy first one.
      grid.compute().execute(SharedResourceTask1.class, null).get();

      checkUsageCount(createClss, UserResource1.class, 2);
      checkUsageCount(createClss, UserResource2.class, 2);

      checkUsageCount(deployClss, UserResource1.class, 2);
      checkUsageCount(deployClss, UserResource2.class, 2);

      // Change class loader of the task. So it's just implicit redeploy.
      ClassLoader tstClsLdr =
          new GridTestClassLoader(
              null,
              getClass().getClassLoader(),
              SharedResourceTask1.class.getName(),
              GridResourceSharedUndeploySelfTest.SharedResourceTask1.GridSharedJob1.class.getName(),
              GridResourceSharedUndeploySelfTest.class.getName());

      Class<? extends GridComputeTask<Object, Object>> taskCls =
          (Class<? extends GridComputeTask<Object, Object>>)
              tstClsLdr.loadClass(SharedResourceTask1.class.getName());

      grid.compute().execute(taskCls, null).get();

      // Old resources should be undeployed at this point.
      checkUsageCount(undeployClss, UserResource1.class, 2);
      checkUsageCount(undeployClss, UserResource2.class, 2);

      // We should detect redeployment and create new resources.
      checkUsageCount(createClss, UserResource1.class, 4);
      checkUsageCount(createClss, UserResource2.class, 4);

      checkUsageCount(deployClss, UserResource1.class, 4);
      checkUsageCount(deployClss, UserResource2.class, 4);
    } finally {
      GridTestUtils.close(grid, log());
    }

    checkUsageCount(undeployClss, UserResource1.class, 4);
    checkUsageCount(undeployClss, UserResource2.class, 4);
  }
コード例 #7
0
  /** @throws Exception If failed. */
  public void testTopologyVersionDrId() throws Exception {
    GridCacheVersion ver = version(10, 0);

    assertEquals(10, ver.nodeOrder());
    assertEquals(0, ver.dataCenterId());

    // Check with max topology version and some dr IDs.
    ver = version(0x7FFFFFF, 0);
    assertEquals(0x7FFFFFF, ver.nodeOrder());
    assertEquals(0, ver.dataCenterId());

    ver = version(0x7FFFFFF, 15);
    assertEquals(0x7FFFFFF, ver.nodeOrder());
    assertEquals(15, ver.dataCenterId());

    ver = version(0x7FFFFFF, 31);
    assertEquals(0x7FFFFFF, ver.nodeOrder());
    assertEquals(31, ver.dataCenterId());

    // Check max dr ID with some topology versions.
    ver = version(11, 31);
    assertEquals(11, ver.nodeOrder());
    assertEquals(31, ver.dataCenterId());

    ver = version(256, 31);
    assertEquals(256, ver.nodeOrder());
    assertEquals(31, ver.dataCenterId());

    ver = version(1025, 31);
    assertEquals(1025, ver.nodeOrder());
    assertEquals(31, ver.dataCenterId());

    // Check overflow exception.
    GridTestUtils.assertThrows(
        log,
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return version(0x7FFFFFF + 1, 1);
          }
        },
        IllegalArgumentException.class,
        null);
  }
コード例 #8
0
  /** @throws Exception If failed. */
  public void testDifferentTaskNameLocally() throws Exception {
    Grid grid = startGrid(0, new GridSpringResourceContextImpl(new GenericApplicationContext()));

    // Versions are different - should not share
    // 2 resource created locally
    try {
      grid.compute().execute(SharedResourceTask1Version1.class, null).get();

      try {
        grid.compute().execute(SharedResourceTask1Version2.class, null).get();

        assert false : "SharedResourceTask4 should not be allowed to deploy.";
      } catch (GridException e) {
        info("Received expected exception: " + e);
      }
    } finally {
      GridTestUtils.close(grid, log());
    }
  }
コード例 #9
0
  /** @throws Exception If failed. */
  public void testSameTaskLocally() throws Exception {
    Grid grid = startGrid(0, new GridSpringResourceContextImpl(new GenericApplicationContext()));

    try {
      // Execute the same task twice.
      // 1 resource created locally
      grid.compute().execute(SharedResourceTask1.class, null).get();
      grid.compute().execute(SharedResourceTask1.class, null).get();

      checkUsageCount(createClss, UserResource1.class, 2);
      checkUsageCount(createClss, UserResource2.class, 2);

      checkUsageCount(deployClss, UserResource1.class, 2);
      checkUsageCount(deployClss, UserResource2.class, 2);
    } finally {
      GridTestUtils.close(grid, log());
    }

    checkUsageCount(undeployClss, UserResource1.class, 2);
    checkUsageCount(undeployClss, UserResource2.class, 2);
  }
コード例 #10
0
  /** @throws Exception If failed. */
  public void testNodeLeave() throws Exception {
    try {
      cache = true;

      for (int i = 0; i < 2; i++) {
        nearOnly = i == 0;

        startGrid(i);
      }

      for (int i = 0; i < 10; i++) grid(1).cache(null).put(i, i);

      final GridCache<Object, Object> nearOnly = grid(0).cache(null);

      // Populate near cache.
      for (int i = 0; i < 10; i++) {
        assertEquals(i, nearOnly.get(i));
        assertEquals(i, nearOnly.peek(i));
      }

      // Stop the only dht node.
      stopGrid(1);

      for (int i = 0; i < 10; i++) {
        assertNull(nearOnly.peek(i));

        final int key = i;

        GridTestUtils.assertThrows(
            log,
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return nearOnly.get(key);
              }
            },
            GridTopologyException.class,
            null);
      }

      // Test optimistic transaction.
      GridTestUtils.assertThrows(
          log,
          new Callable<Object>() {
            @Override
            public Object call() throws Exception {
              try (GridCacheTx tx = nearOnly.txStart(OPTIMISTIC, REPEATABLE_READ)) {
                nearOnly.putx("key", "val");

                tx.commit();
              }

              return null;
            }
          },
          GridTopologyException.class,
          null);

      // Test pessimistic transaction.
      GridTestUtils.assertThrows(
          log,
          new Callable<Object>() {
            @Override
            public Object call() throws Exception {
              try (GridCacheTx tx = nearOnly.txStart(PESSIMISTIC, REPEATABLE_READ)) {
                nearOnly.put("key", "val");

                tx.commit();
              }

              return null;
            }
          },
          GridTopologyException.class,
          null);

    } finally {
      stopAllGrids();
    }
  }
コード例 #11
0
  /** @throws Exception If failed. */
  public void testEmptyProjections() throws Exception {
    final GridClientCompute dflt = client.compute();

    Collection<? extends GridClientNode> nodes = dflt.nodes();

    assertEquals(NODES_CNT, nodes.size());

    Iterator<? extends GridClientNode> iter = nodes.iterator();

    final GridClientCompute singleNodePrj = dflt.projection(Collections.singletonList(iter.next()));

    final GridClientNode second = iter.next();

    final GridClientPredicate<GridClientNode> noneFilter =
        new GridClientPredicate<GridClientNode>() {
          @Override
          public boolean apply(GridClientNode node) {
            return false;
          }
        };

    final GridClientPredicate<GridClientNode> targetFilter =
        new GridClientPredicate<GridClientNode>() {
          @Override
          public boolean apply(GridClientNode node) {
            return node.nodeId().equals(second.nodeId());
          }
        };

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return dflt.projection(noneFilter).log(-1, -1);
          }
        },
        GridServerUnreachableException.class,
        null);

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return singleNodePrj.projection(second);
          }
        },
        GridClientException.class,
        null);

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return singleNodePrj.projection(targetFilter);
          }
        },
        GridClientException.class,
        null);
  }