use of org.apache.bookkeeper.mledger.LedgerOffloader in project pulsar by apache.
the class OffloadLedgerDeleteTest method isOffloadedNeedsDeleteTest.
@Test
public void isOffloadedNeedsDeleteTest() throws Exception {
OffloadPoliciesImpl offloadPolicies = new OffloadPoliciesImpl();
LedgerOffloader ledgerOffloader = Mockito.mock(LedgerOffloader.class);
Mockito.when(ledgerOffloader.getOffloadPolicies()).thenReturn(offloadPolicies);
ManagedLedgerConfig config = new ManagedLedgerConfig();
MockClock clock = new MockClock();
config.setLedgerOffloader(ledgerOffloader);
config.setClock(clock);
ManagedLedgerImpl managedLedger = (ManagedLedgerImpl) factory.open("isOffloadedNeedsDeleteTest", config);
MLDataFormats.OffloadContext offloadContext = MLDataFormats.OffloadContext.newBuilder().setTimestamp(config.getClock().millis() - 1000).setComplete(true).setBookkeeperDeleted(false).build();
boolean needsDelete = managedLedger.isOffloadedNeedsDelete(offloadContext, Optional.of(offloadPolicies));
Assert.assertFalse(needsDelete);
offloadPolicies.setManagedLedgerOffloadDeletionLagInMillis(500L);
needsDelete = managedLedger.isOffloadedNeedsDelete(offloadContext, Optional.of(offloadPolicies));
Assert.assertTrue(needsDelete);
offloadPolicies.setManagedLedgerOffloadDeletionLagInMillis(1000L * 2);
needsDelete = managedLedger.isOffloadedNeedsDelete(offloadContext, Optional.of(offloadPolicies));
Assert.assertFalse(needsDelete);
offloadContext = MLDataFormats.OffloadContext.newBuilder().setTimestamp(config.getClock().millis() - 1000).setComplete(false).setBookkeeperDeleted(false).build();
needsDelete = managedLedger.isOffloadedNeedsDelete(offloadContext, Optional.of(offloadPolicies));
Assert.assertFalse(needsDelete);
offloadContext = MLDataFormats.OffloadContext.newBuilder().setTimestamp(config.getClock().millis() - 1000).setComplete(true).setBookkeeperDeleted(true).build();
needsDelete = managedLedger.isOffloadedNeedsDelete(offloadContext, Optional.of(offloadPolicies));
Assert.assertFalse(needsDelete);
}
Aggregations