@Test(timeout = 60_000L) public void testRepeatInsert() throws Exception { final String entryId = "abcd"; Map<String, Integer> entry = ImmutableMap.of("a", 1); Map<String, Integer> status = ImmutableMap.of("count", 42); handler.insert(entryId, DateTimes.of("2014-01-01"), "test", entry, true, status); thrown.expect(EntryExistsException.class); handler.insert(entryId, DateTimes.of("2014-01-01"), "test", entry, true, status); }
Map<String, Integer> status = ImmutableMap.of("count", 42); handler.insert(entryId, DateTimes.of("2014-01-01"), "test", entry, true, status);
@Test public void testGetRecentStatuses() throws EntryExistsException { for (int i = 1; i < 11; i++) { final String entryId = "abcd_" + i; final Map<String, Integer> entry = ImmutableMap.of("a", i); final Map<String, Integer> status = ImmutableMap.of("count", i * 10); handler.insert(entryId, DateTimes.of(StringUtils.format("2014-01-%02d", i)), "test", entry, false, status); } final List<TaskInfo<Map<String, Integer>, Map<String, Integer>>> statuses = handler.getCompletedTaskInfo( DateTimes.of("2014-01-01"), 7, null ); Assert.assertEquals(7, statuses.size()); int i = 10; for (TaskInfo<Map<String, Integer>, Map<String, Integer>> status : statuses) { Assert.assertEquals(ImmutableMap.of("count", i-- * 10), status.getStatus()); } }
@Test public void testGetRecentStatuses2() throws EntryExistsException { for (int i = 1; i < 6; i++) { final String entryId = "abcd_" + i; final Map<String, Integer> entry = ImmutableMap.of("a", i); final Map<String, Integer> status = ImmutableMap.of("count", i * 10); handler.insert(entryId, DateTimes.of(StringUtils.format("2014-01-%02d", i)), "test", entry, false, status); } final List<TaskInfo<Map<String, Integer>, Map<String, Integer>>> statuses = handler.getCompletedTaskInfo( DateTimes.of("2014-01-01"), 10, null ); Assert.assertEquals(5, statuses.size()); int i = 5; for (TaskInfo<Map<String, Integer>, Map<String, Integer>> status : statuses) { Assert.assertEquals(ImmutableMap.of("count", i-- * 10), status.getStatus()); } }
@Test public void testLogs() throws Exception { final String entryId = "abcd"; Map<String, Integer> entry = ImmutableMap.of("a", 1); Map<String, Integer> status = ImmutableMap.of("count", 42); handler.insert(entryId, DateTimes.of("2014-01-01"), "test", entry, true, status); Assert.assertEquals( ImmutableList.of(), handler.getLogs("non_exist_entry") ); Assert.assertEquals( ImmutableMap.of(), handler.getLocks(entryId) ); final ImmutableMap<String, String> log1 = ImmutableMap.of("logentry", "created"); final ImmutableMap<String, String> log2 = ImmutableMap.of("logentry", "updated"); Assert.assertTrue(handler.addLog(entryId, log1)); Assert.assertTrue(handler.addLog(entryId, log2)); Assert.assertEquals( ImmutableList.of(log1, log2), handler.getLogs(entryId) ); }
@Test public void testGetLockId() throws EntryExistsException { final String entryId = "ABC123"; Map<String, Integer> entry = ImmutableMap.of("a", 1); Map<String, Integer> status = ImmutableMap.of("count", 42); handler.insert(entryId, DateTimes.of("2014-01-01"), "test", entry, true, status); Assert.assertEquals( ImmutableMap.<Long, Map<String, Integer>>of(), handler.getLocks("non_exist_entry") ); Assert.assertEquals( ImmutableMap.<Long, Map<String, Integer>>of(), handler.getLocks(entryId) ); final ImmutableMap<String, Integer> lock1 = ImmutableMap.of("lock", 1); final ImmutableMap<String, Integer> lock2 = ImmutableMap.of("lock", 2); Assert.assertTrue(handler.addLock(entryId, lock1)); Assert.assertNotNull(handler.getLockId(entryId, lock1)); Assert.assertNull(handler.getLockId(entryId, lock2)); }
@Test public void testReplaceLock() throws EntryExistsException { final String entryId = "ABC123"; Map<String, Integer> entry = ImmutableMap.of("a", 1); Map<String, Integer> status = ImmutableMap.of("count", 42); handler.insert(entryId, DateTimes.of("2014-01-01"), "test", entry, true, status); Assert.assertEquals( ImmutableMap.<Long, Map<String, Integer>>of(), handler.getLocks("non_exist_entry") ); Assert.assertEquals( ImmutableMap.<Long, Map<String, Integer>>of(), handler.getLocks(entryId) ); final ImmutableMap<String, Integer> lock1 = ImmutableMap.of("lock", 1); final ImmutableMap<String, Integer> lock2 = ImmutableMap.of("lock", 2); Assert.assertTrue(handler.addLock(entryId, lock1)); final Long lockId1 = handler.getLockId(entryId, lock1); Assert.assertNotNull(lockId1); Assert.assertTrue(handler.replaceLock(entryId, lockId1, lock2)); }
Map<String, Integer> entry1 = ImmutableMap.of("numericId", 1234); Map<String, Integer> status1 = ImmutableMap.of("count", 42, "temp", 1); handler.insert(entryId1, DateTimes.of("2014-01-01T00:00:00.123"), "testDataSource", entry1, false, status1); Assert.assertTrue(handler.addLog(entryId1, ImmutableMap.of("logentry", "created"))); Map<String, Integer> entry2 = ImmutableMap.of("a", 1); Map<String, Integer> status2 = ImmutableMap.of("count", 42); handler.insert(entryId2, DateTimes.of("2014-01-01T00:00:00.123"), "test", entry2, true, status2); Assert.assertTrue(handler.addLog(entryId2, ImmutableMap.of("logentry", "created"))); Map<String, Integer> entry3 = ImmutableMap.of("numericId", 5678); Map<String, Integer> status3 = ImmutableMap.of("count", 21, "temp", 2); handler.insert(entryId3, DateTimes.of("2014-01-02T12:00:00.123"), "testDataSource", entry3, false, status3); Assert.assertTrue(handler.addLog(entryId3, ImmutableMap.of("logentry", "created")));
handler.insert(entryId, DateTimes.of("2014-01-02T00:00:00.123"), "testDataSource", entry, true, null);