public static LogRecordWithDLSN getLogRecordWithDLSNInstance(DLSN dlsn, long txId) { return getLogRecordWithDLSNInstance(dlsn, txId, false); }
@Test(timeout = 60000) public void testGetEntriesToSearchByTxnId() throws Exception { LogRecordWithDLSN firstRecord = DLMTestUtil.getLogRecordWithDLSNInstance(new DLSN(1L, 0L, 0L), 999L); LogRecordWithDLSN secondRecord = DLMTestUtil.getLogRecordWithDLSNInstance(new DLSN(1L, 10L, 0L), 99L); LogRecordWithDLSN thirdRecord = DLMTestUtil.getLogRecordWithDLSNInstance(new DLSN(1L, 100L, 0L), 1099L); // out-of-order sequence assertTrue(ReadUtils.getEntriesToSearch(888L, firstRecord, secondRecord, 10).isEmpty()); // same transaction id assertTrue(ReadUtils.getEntriesToSearch(888L, firstRecord, firstRecord, 10).isEmpty()); // small nways (nways = 2) assertEquals(2, ReadUtils.getEntriesToSearch(888L, firstRecord, thirdRecord, 2).size()); // small nways with equal transaction id assertEquals(3, ReadUtils.getEntriesToSearch(1099L, firstRecord, thirdRecord, 2).size()); LogRecordWithDLSN record1 = DLMTestUtil.getLogRecordWithDLSNInstance(new DLSN(1L, 0L, 0L), 88L); LogRecordWithDLSN record2 = DLMTestUtil.getLogRecordWithDLSNInstance(new DLSN(1L, 12L, 0L), 888L); LogRecordWithDLSN record3 = DLMTestUtil.getLogRecordWithDLSNInstance(new DLSN(1L, 12L, 0L), 999L); assertEquals(Lists.newArrayList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 10L, 11L), ReadUtils.getEntriesToSearch(888L, record1, record2, 10)); assertEquals(Lists.newArrayList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L), ReadUtils.getEntriesToSearch(888L, record1, record3, 10)); }
@Test(timeout = 60000) public void testFirstRecordSelector() { FirstRecordSelector selectorIncludeControlRecord = new FirstRecordSelector(true); for (int i = 0; i < 5; i++) { selectorIncludeControlRecord.process( DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(1L, i * 2, 0L), i * 2, true)); selectorIncludeControlRecord.process( DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(1L, i * 2 + 1, 0L), i * 2 + 1)); } assertEquals(new DLSN(1L, 0L, 0L), selectorIncludeControlRecord.result().getDlsn()); FirstRecordSelector selectorExcludeControlRecord = new FirstRecordSelector(false); for (int i = 0; i < 5; i++) { selectorExcludeControlRecord.process( DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(1L, i * 2, 0L), i * 2, true)); selectorExcludeControlRecord.process( DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(1L, i * 2 + 1, 0L), i * 2 + 1)); } assertEquals(new DLSN(1L, 1L, 0L), selectorExcludeControlRecord.result().getDlsn()); }
@Test(timeout = 60000) public void testLastRecordSelector() { LastRecordSelector selector = new LastRecordSelector(); for (int i = 0; i < 10; i++) { selector.process(DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(1L, i, 0L), i)); } assertEquals(new DLSN(1L, 9L, 0L), selector.result().getDlsn()); }
@Test(timeout = 60000) public void testFirstTxIdNotLessThanSelector() { long txId = 5 * 10 + 5; FirstTxIdNotLessThanSelector largerSelector = new FirstTxIdNotLessThanSelector(txId); for (int i = 0; i < 10; i++) { largerSelector.process(DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(4L, i, 0L), 4 * 10 + i)); } assertEquals(49, largerSelector.result().getTransactionId()); FirstTxIdNotLessThanSelector smallerSelector = new FirstTxIdNotLessThanSelector(txId); for (int i = 0; i < 10; i++) { smallerSelector.process(DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(6L, i, 0L), 6 * 10 + i)); } assertEquals(6 * 10, smallerSelector.result().getTransactionId()); FirstTxIdNotLessThanSelector selector = new FirstTxIdNotLessThanSelector(txId); for (int i = 0; i < 10; i++) { selector.process(DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(5L, i, 0L), 5 * 10 + i)); } assertEquals(txId, selector.result().getTransactionId()); } }
@Test(timeout = 60000) public void testFirstDLSNNotLessThanSelector() { DLSN dlsn = new DLSN(5L, 5L, 0L); FirstDLSNNotLessThanSelector largerSelector = new FirstDLSNNotLessThanSelector(dlsn); for (int i = 0; i < 10; i++) { largerSelector.process(DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(4L, i, 0L), i)); } assertNull(largerSelector.result()); FirstDLSNNotLessThanSelector smallerSelector = new FirstDLSNNotLessThanSelector(dlsn); for (int i = 0; i < 10; i++) { smallerSelector.process(DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(6L, i, 0L), i)); } assertEquals(new DLSN(6L, 0L, 0L), smallerSelector.result().getDlsn()); FirstDLSNNotLessThanSelector selector = new FirstDLSNNotLessThanSelector(dlsn); for (int i = 0; i < 10; i++) { selector.process(DLMTestUtil.getLogRecordWithDLSNInstance( new DLSN(5L, i, 0L), i)); } assertEquals(dlsn, selector.result().getDlsn()); }
DLSN goodLastDLSN2 = new DLSN(2L, 200L, 0L); LogRecordWithDLSN badRecord = DLMTestUtil.getLogRecordWithDLSNInstance(badLastDLSN, 100L); LogRecordWithDLSN goodRecord1 = DLMTestUtil.getLogRecordWithDLSNInstance(goodLastDLSN1, 100L); LogRecordWithDLSN goodRecord2 = DLMTestUtil.getLogRecordWithDLSNInstance(goodLastDLSN2, 200L);