Search in sources :

Example 91 with LedgerOffloader

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);
}
Also used : OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) MLDataFormats(org.apache.bookkeeper.mledger.proto.MLDataFormats) LedgerOffloader(org.apache.bookkeeper.mledger.LedgerOffloader) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) MockClock(org.apache.bookkeeper.mledger.util.MockClock) Test(org.testng.annotations.Test)

Aggregations

LedgerOffloader (org.apache.bookkeeper.mledger.LedgerOffloader)91 Test (org.testng.annotations.Test)72 HashMap (java.util.HashMap)58 UUID (java.util.UUID)53 ReadHandle (org.apache.bookkeeper.client.api.ReadHandle)45 LedgerEntries (org.apache.bookkeeper.client.api.LedgerEntries)28 LedgerEntry (org.apache.bookkeeper.client.api.LedgerEntry)28 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)24 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)22 OffloadHandle (org.apache.bookkeeper.mledger.LedgerOffloader.OffloadHandle)18 OffloadPoliciesImpl (org.apache.pulsar.common.policies.data.OffloadPoliciesImpl)18 LinkedList (java.util.LinkedList)17 Entry (org.apache.bookkeeper.mledger.Entry)15 EntryImpl (org.apache.bookkeeper.mledger.impl.EntryImpl)15 OffloadContext (org.apache.bookkeeper.mledger.proto.MLDataFormats.OffloadContext)15 CompletableFuture (java.util.concurrent.CompletableFuture)13 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)12 Map (java.util.Map)9 ExecutionException (java.util.concurrent.ExecutionException)9 BKException (org.apache.bookkeeper.client.BKException)9