Search in sources :

Example 1 with SingularityPendingRequestPrevious

use of com.hubspot.singularity.data.zkmigrations.SingularityCmdLineArgsMigration.SingularityPendingRequestPrevious in project Singularity by HubSpot.

the class ZkMigrationTest method testCmdLineArgsMigration.

@Test
public void testCmdLineArgsMigration() throws Exception {
    metadataManager.setZkDataVersion("2");
    // save some old stuff
    SingularityPendingRequestPrevious p1 = new SingularityPendingRequestPrevious("r1", "d1", 23L, Optional.<String>absent(), PendingType.BOUNCE, Optional.<String>absent());
    SingularityPendingRequestPrevious p2 = new SingularityPendingRequestPrevious("r2", "d3", 123L, Optional.of("user1"), PendingType.BOUNCE, Optional.of("cmd line args"));
    byte[] p1b = objectMapper.writeValueAsBytes(p1);
    byte[] p2b = objectMapper.writeValueAsBytes(p2);
    curator.create().creatingParentsIfNeeded().forPath(getPendingPath("r1", "d1"), p1b);
    curator.create().creatingParentsIfNeeded().forPath(getPendingPath("r2", "de"), p2b);
    SingularityPendingTaskId pt1 = new SingularityPendingTaskId("r1", "d1", 23L, 3, PendingType.BOUNCE, 1L);
    SingularityPendingTaskId pt2 = new SingularityPendingTaskId("r2", "d3", 231L, 1, PendingType.UNPAUSED, 23L);
    curator.create().creatingParentsIfNeeded().forPath(getPendingPath(pt1));
    curator.create().creatingParentsIfNeeded().forPath(getPendingPath(pt2), StringTranscoder.INSTANCE.toBytes("cmd line args"));
    migrationRunner.checkMigrations();
    Assert.assertTrue(!taskManager.getPendingTask(pt1).get().getCmdLineArgsList().isPresent());
    Assert.assertTrue(taskManager.getPendingTask(pt2).get().getCmdLineArgsList().get().get(0).equals("cmd line args"));
    Assert.assertTrue(taskManager.getPendingTask(pt2).get().getCmdLineArgsList().get().size() == 1);
    Assert.assertTrue(taskManager.getPendingTaskIds().contains(pt1));
    Assert.assertTrue(taskManager.getPendingTaskIds().contains(pt2));
    Assert.assertTrue(requestManager.getPendingRequests().size() == 2);
    for (SingularityPendingRequest r : requestManager.getPendingRequests()) {
        if (r.getRequestId().equals("r1")) {
            Assert.assertEquals(r.getDeployId(), p1.getDeployId());
            Assert.assertEquals(r.getTimestamp(), p1.getTimestamp());
            Assert.assertEquals(r.getPendingType(), p1.getPendingType());
            Assert.assertTrue(!r.getCmdLineArgsList().isPresent());
            Assert.assertEquals(r.getUser(), p1.getUser());
        } else {
            Assert.assertEquals(r.getDeployId(), p2.getDeployId());
            Assert.assertEquals(r.getTimestamp(), p2.getTimestamp());
            Assert.assertEquals(r.getPendingType(), p2.getPendingType());
            Assert.assertTrue(r.getCmdLineArgsList().get().size() == 1);
            Assert.assertTrue(r.getCmdLineArgsList().get().get(0).equals("cmd line args"));
            Assert.assertEquals(r.getUser(), p2.getUser());
        }
    }
}
Also used : SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityPendingRequestPrevious(com.hubspot.singularity.data.zkmigrations.SingularityCmdLineArgsMigration.SingularityPendingRequestPrevious) Test(org.junit.Test)

Aggregations

SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)1 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)1 SingularityPendingRequestPrevious (com.hubspot.singularity.data.zkmigrations.SingularityCmdLineArgsMigration.SingularityPendingRequestPrevious)1 Test (org.junit.Test)1