Search in sources :

Example 1 with MetadataStoreException

use of org.apache.pulsar.metadata.api.MetadataStoreException in project pulsar by apache.

the class ManagedLedgerErrorsTest method errorInRecovering5.

@Test
public void errorInRecovering5() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.addEntry("entry".getBytes());
    ledger.close();
    @Cleanup("shutdown") ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(metadataStore, bkc);
    metadataStore.failConditional(new MetadataStoreException("error"), (op, path) -> path.equals("/managed-ledgers/my_test_ledger") && op == FaultInjectionMetadataStore.OperationType.GET_CHILDREN);
    try {
        ledger = factory2.open("my_test_ledger");
        fail("should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    // It should be fine now
    ledger = factory2.open("my_test_ledger");
}
Also used : MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) Cleanup(lombok.Cleanup) Test(org.testng.annotations.Test)

Example 2 with MetadataStoreException

use of org.apache.pulsar.metadata.api.MetadataStoreException in project pulsar by apache.

the class ManagedLedgerErrorsTest method errorInRecovering6.

@Test
public void errorInRecovering6() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.openCursor("c1");
    ledger.addEntry("entry".getBytes());
    ledger.close();
    @Cleanup("shutdown") ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(metadataStore, bkc);
    metadataStore.failConditional(new MetadataStoreException("error"), (op, path) -> path.equals("/managed-ledgers/my_test_ledger/c1") && op == FaultInjectionMetadataStore.OperationType.GET);
    try {
        ledger = factory2.open("my_test_ledger");
        fail("should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    // It should be fine now
    ledger = factory2.open("my_test_ledger");
}
Also used : MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) Cleanup(lombok.Cleanup) Test(org.testng.annotations.Test)

Example 3 with MetadataStoreException

use of org.apache.pulsar.metadata.api.MetadataStoreException in project pulsar by apache.

the class PersistentTopicsTest method testDeleteTopic.

@Test
public void testDeleteTopic() throws Exception {
    final String topicName = "topic-1";
    BrokerService brokerService = spy(pulsar.getBrokerService());
    doReturn(brokerService).when(pulsar).getBrokerService();
    persistentTopics.createNonPartitionedTopic(testTenant, testNamespace, topicName, false, null);
    CompletableFuture<Void> deleteTopicFuture = new CompletableFuture<>();
    deleteTopicFuture.completeExceptionally(new MetadataStoreException.NotFoundException());
    doReturn(deleteTopicFuture).when(brokerService).deleteTopic(anyString(), anyBoolean(), anyBoolean());
    persistentTopics.deleteTopic(testTenant, testNamespace, topicName, true, true, true);
    // 
    CompletableFuture<Void> deleteTopicFuture2 = new CompletableFuture<>();
    deleteTopicFuture2.completeExceptionally(new MetadataStoreException("test exception"));
    doReturn(deleteTopicFuture2).when(brokerService).deleteTopic(anyString(), anyBoolean(), anyBoolean());
    try {
        persistentTopics.deleteTopic(testTenant, testNamespace, topicName, true, true, true);
    } catch (Exception e) {
        Assert.assertTrue(e instanceof RestException);
    }
    // 
    CompletableFuture<Void> deleteTopicFuture3 = new CompletableFuture<>();
    deleteTopicFuture3.completeExceptionally(new MetadataStoreException.NotFoundException());
    doReturn(deleteTopicFuture3).when(brokerService).deleteTopic(anyString(), anyBoolean(), anyBoolean());
    try {
        persistentTopics.deleteTopic(testTenant, testNamespace, topicName, false, true, true);
    } catch (RestException e) {
        Assert.assertEquals(e.getResponse().getStatus(), 404);
    }
}
Also used : MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) CompletableFuture(java.util.concurrent.CompletableFuture) RestException(org.apache.pulsar.broker.web.RestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BrokerService(org.apache.pulsar.broker.service.BrokerService) RestException(org.apache.pulsar.broker.web.RestException) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) WebApplicationException(javax.ws.rs.WebApplicationException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 4 with MetadataStoreException

use of org.apache.pulsar.metadata.api.MetadataStoreException in project pulsar by apache.

the class ManagedCursorTest method errorCreatingCursor.

@Test(timeOut = 20000)
void errorCreatingCursor() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    bkc.failAfter(1, BKException.Code.NotEnoughBookiesException);
    metadataStore.failConditional(new MetadataStoreException("error"), (op, path) -> path.equals("/managed-ledgers/my_test_ledger/c1") && op == FaultInjectionMetadataStore.OperationType.PUT);
    try {
        ledger.openCursor("c1");
        fail("should have failed");
    } catch (ManagedLedgerException e) {
    // ok
    }
}
Also used : MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 5 with MetadataStoreException

use of org.apache.pulsar.metadata.api.MetadataStoreException in project pulsar by apache.

the class ManagedCursorTest method markDeleteWithZKErrors.

@Test(timeOut = 20000)
void markDeleteWithZKErrors() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursor cursor = ledger.openCursor("c1");
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    List<Entry> entries = cursor.readEntries(100);
    assertEquals(entries.size(), 1);
    stopBookKeeper();
    metadataStore.setAlwaysFail(new MetadataStoreException("error"));
    try {
        cursor.markDelete(entries.get(0).getPosition());
        fail("Should have failed");
    } catch (Exception e) {
    // Expected
    }
    entries.forEach(e -> e.release());
}
Also used : MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) Entry(org.apache.bookkeeper.mledger.Entry) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) BKException(org.apache.bookkeeper.client.BKException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Aggregations

MetadataStoreException (org.apache.pulsar.metadata.api.MetadataStoreException)24 Test (org.testng.annotations.Test)15 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)11 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)10 CompletableFuture (java.util.concurrent.CompletableFuture)8 Optional (java.util.Optional)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Collections (java.util.Collections)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 FutureUtil (org.apache.pulsar.common.util.FutureUtil)4 Notification (org.apache.pulsar.metadata.api.Notification)4 NotificationType (org.apache.pulsar.metadata.api.NotificationType)4 Stat (org.apache.pulsar.metadata.api.Stat)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Cleanup (lombok.Cleanup)3 MetaStoreException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)3