コード例 #1
0
  @Test
  public void testRestartCleansOldStatus() throws Exception {
    cf.create()
        .creatingParentsIfNeeded()
        .forPath(joiner.join(tasksPath, task.getId()), jsonMapper.writeValueAsBytes(task));

    Assert.assertTrue(
        TestUtils.conditionValid(
            new IndexingServiceCondition() {
              @Override
              public boolean isValid() {
                try {
                  return cf.checkExists().forPath(joiner.join(statusPath, task.getId())) != null;
                } catch (Exception e) {
                  return false;
                }
              }
            }));
    // simulate node restart
    workerTaskMonitor.stop();
    workerTaskMonitor = createTaskMonitor();
    workerTaskMonitor.start();
    List<TaskAnnouncement> announcements = workerCuratorCoordinator.getAnnouncements();
    Assert.assertEquals(1, announcements.size());
    Assert.assertEquals(task.getId(), announcements.get(0).getTaskStatus().getId());
    Assert.assertEquals(
        TaskStatus.Status.FAILED, announcements.get(0).getTaskStatus().getStatusCode());
  }
コード例 #2
-1
  @Before
  public void setUp() throws Exception {
    testingCluster = new TestingCluster(1);
    testingCluster.start();

    cf =
        CuratorFrameworkFactory.builder()
            .connectString(testingCluster.getConnectString())
            .retryPolicy(new ExponentialBackoffRetry(1, 10))
            .compressionProvider(new PotentiallyGzippedCompressionProvider(false))
            .build();
    cf.start();
    cf.create().creatingParentsIfNeeded().forPath(basePath);

    worker = new Worker("worker", "localhost", 3, "0");

    workerCuratorCoordinator =
        new WorkerCuratorCoordinator(
            jsonMapper,
            new IndexerZkConfig(
                new ZkPathsConfig() {
                  @Override
                  public String getBase() {
                    return basePath;
                  }
                },
                null,
                null,
                null,
                null,
                null),
            new TestRemoteTaskRunnerConfig(new Period("PT1S")),
            cf,
            worker);
    workerCuratorCoordinator.start();

    // Start a task monitor
    workerTaskMonitor = createTaskMonitor();
    jsonMapper.registerSubtypes(new NamedType(TestMergeTask.class, "test"));
    jsonMapper.registerSubtypes(new NamedType(TestRealtimeTask.class, "test_realtime"));
    workerTaskMonitor.start();

    task = TestMergeTask.createDummyTask("test");
  }