Search in sources :

Example 1 with SameThreadOrderedSafeExecutor

use of org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor in project pulsar by apache.

the class OwnerShipForCurrentServerTestBase method setupBrokerMocks.

protected void setupBrokerMocks(PulsarService pulsar) throws Exception {
    // Override default providers with mocked ones
    doReturn(mockBookKeeperClientFactory).when(pulsar).newBookKeeperClientFactory();
    MockZooKeeperSession mockZooKeeperSession = MockZooKeeperSession.newInstance(mockZooKeeper);
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createLocalMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createConfigurationMetadataStore();
    Supplier<NamespaceService> namespaceServiceSupplier = () -> spyWithClassAndConstructorArgs(NamespaceService.class, pulsar);
    doReturn(namespaceServiceSupplier).when(pulsar).getNamespaceServiceProvider();
    SameThreadOrderedSafeExecutor executor = new SameThreadOrderedSafeExecutor();
    orderedExecutorList.add(executor);
    doReturn(executor).when(pulsar).getOrderedExecutor();
    doReturn(new CounterBrokerInterceptor()).when(pulsar).getBrokerInterceptor();
    doAnswer((invocation) -> spy(invocation.callRealMethod())).when(pulsar).newCompactor();
}
Also used : CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) MockZooKeeperSession(org.apache.zookeeper.MockZooKeeperSession) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore)

Example 2 with SameThreadOrderedSafeExecutor

use of org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor in project kop by streamnative.

the class KopProtocolHandlerTestBase method internalSetup.

protected final void internalSetup() throws Exception {
    sameThreadOrderedSafeExecutor = new SameThreadOrderedSafeExecutor();
    bkExecutor = OrderedScheduler.newSchedulerBuilder().numThreads(2).name("mock-pulsar-bk").build();
    brokerUrl = new URL("http://" + getAdvertisedAddress() + ":" + brokerWebservicePort);
    brokerUrlTls = new URL("https://" + getAdvertisedAddress() + ":" + brokerWebservicePortTls);
    String serviceUrl = "http://" + getAdvertisedAddress() + ":" + brokerWebservicePort;
    String serviceUrlTls = "https://" + getAdvertisedAddress() + ":" + brokerWebservicePortTls;
    String brokerServiceUrl = "pulsar://" + getAdvertisedAddress() + ":" + brokerPort;
    // TLS not supported at this time
    String brokerServiceUrlTls = null;
    clusterData = ClusterData.builder().serviceUrl(serviceUrl).serviceUrlTls(serviceUrlTls).brokerServiceUrl(brokerServiceUrl).brokerServiceUrlTls(brokerServiceUrlTls).build();
    mockZooKeeper = createMockZooKeeper(configClusterName, serviceUrl, serviceUrlTls, brokerServiceUrl, brokerServiceUrlTls);
    mockBookKeeper = createMockBookKeeper(bkExecutor);
    startBroker();
    createAdmin();
    createClient();
    MetadataUtils.createOffsetMetadataIfMissing(conf.getKafkaMetadataTenant(), admin, clusterData, this.conf);
    if (conf.isKafkaTransactionCoordinatorEnabled()) {
        MetadataUtils.createTxnMetadataIfMissing(conf.getKafkaMetadataTenant(), admin, clusterData, this.conf);
    }
    if (enableSchemaRegistry) {
        admin.topics().createPartitionedTopic(KAFKASTORE_TOPIC, 1);
        final Properties props = new Properties();
        props.put(SchemaRegistryConfig.PORT_CONFIG, Integer.toString(getKafkaSchemaRegistryPort()));
        // Increase the kafkastore.timeout.ms (default: 500) to avoid test failure in CI
        props.put(SchemaRegistryConfig.KAFKASTORE_TIMEOUT_CONFIG, 3000);
        // NOTE: KoP doesn't support kafkastore.connection.url
        props.put(SchemaRegistryConfig.KAFKASTORE_BOOTSTRAP_SERVERS_CONFIG, "PLAINTEXT://localhost:" + getKafkaBrokerPort());
        props.put(SchemaRegistryConfig.KAFKASTORE_TOPIC_CONFIG, KAFKASTORE_TOPIC);
        props.put(SchemaRegistryConfig.COMPATIBILITY_CONFIG, AvroCompatibilityLevel.NONE.name);
        props.put(SchemaRegistryConfig.MASTER_ELIGIBILITY, true);
        restApp = new SchemaRegistryRestApplication(props);
        restServer = restApp.createServer();
        restServer.start();
        restConnect = restServer.getURI().toString();
        if (restConnect.endsWith("/")) {
            restConnect = restConnect.substring(0, restConnect.length() - 1);
        }
    }
}
Also used : SchemaRegistryRestApplication(io.confluent.kafka.schemaregistry.rest.SchemaRegistryRestApplication) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) Properties(java.util.Properties) URL(java.net.URL)

Example 3 with SameThreadOrderedSafeExecutor

use of org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor in project pulsar by yahoo.

the class OwnerShipForCurrentServerTestBase method setupBrokerMocks.

protected void setupBrokerMocks(PulsarService pulsar) throws Exception {
    // Override default providers with mocked ones
    doReturn(mockBookKeeperClientFactory).when(pulsar).newBookKeeperClientFactory();
    MockZooKeeperSession mockZooKeeperSession = MockZooKeeperSession.newInstance(mockZooKeeper);
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createLocalMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createConfigurationMetadataStore();
    Supplier<NamespaceService> namespaceServiceSupplier = () -> spyWithClassAndConstructorArgs(NamespaceService.class, pulsar);
    doReturn(namespaceServiceSupplier).when(pulsar).getNamespaceServiceProvider();
    SameThreadOrderedSafeExecutor executor = new SameThreadOrderedSafeExecutor();
    orderedExecutorList.add(executor);
    doReturn(executor).when(pulsar).getOrderedExecutor();
    doReturn(new CounterBrokerInterceptor()).when(pulsar).getBrokerInterceptor();
    doAnswer((invocation) -> spy(invocation.callRealMethod())).when(pulsar).newCompactor();
}
Also used : CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) MockZooKeeperSession(org.apache.zookeeper.MockZooKeeperSession) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore)

Example 4 with SameThreadOrderedSafeExecutor

use of org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor in project pulsar by yahoo.

the class OwnerShipForCurrentServerTestBase method internalCleanup.

protected final void internalCleanup() {
    try {
        // an NPE in shutdown, obscuring the real error
        if (admin != null) {
            admin.close();
            admin = null;
        }
        if (pulsarClient != null) {
            pulsarClient.shutdown();
            pulsarClient = null;
        }
        if (pulsarServiceList.size() > 0) {
            for (PulsarService pulsarService : pulsarServiceList) {
                pulsarService.close();
            }
            pulsarServiceList.clear();
        }
        if (serviceConfigurationList.size() > 0) {
            serviceConfigurationList.clear();
        }
        if (mockBookKeeper != null) {
            mockBookKeeper.reallyShutdown();
        }
        if (mockZooKeeper != null) {
            mockZooKeeper.shutdown();
        }
        if (orderedExecutorList.size() > 0) {
            for (int i = 0; i < orderedExecutorList.size(); i++) {
                SameThreadOrderedSafeExecutor sameThreadOrderedSafeExecutor = orderedExecutorList.get(i);
                if (sameThreadOrderedSafeExecutor != null) {
                    try {
                        sameThreadOrderedSafeExecutor.shutdownNow();
                        sameThreadOrderedSafeExecutor.awaitTermination(5, TimeUnit.SECONDS);
                    } catch (InterruptedException ex) {
                        log.error("sameThreadOrderedSafeExecutor shutdown had error", ex);
                        Thread.currentThread().interrupt();
                    }
                    orderedExecutorList.set(i, null);
                }
            }
        }
        if (bkExecutor != null) {
            try {
                bkExecutor.shutdownNow();
                bkExecutor.awaitTermination(5, TimeUnit.SECONDS);
            } catch (InterruptedException ex) {
                log.error("bkExecutor shutdown had error", ex);
                Thread.currentThread().interrupt();
            }
            bkExecutor = null;
        }
    } catch (Exception e) {
        log.warn("Failed to clean up mocked pulsar service:", e);
    }
}
Also used : PulsarService(org.apache.pulsar.broker.PulsarService) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor)

Example 5 with SameThreadOrderedSafeExecutor

use of org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor in project pulsar by yahoo.

the class TransactionTestBase method internalCleanup.

protected final void internalCleanup() {
    markCurrentSetupNumberCleaned();
    try {
        // an NPE in shutdown, obscuring the real error
        if (admin != null) {
            admin.close();
            admin = null;
        }
        if (pulsarClient != null) {
            pulsarClient.close();
            pulsarClient = null;
        }
        if (pulsarServiceList.size() > 0) {
            for (PulsarService pulsarService : pulsarServiceList) {
                pulsarService.close();
            }
            pulsarServiceList.clear();
        }
        if (serviceConfigurationList.size() > 0) {
            serviceConfigurationList.clear();
        }
        if (mockBookKeeper != null) {
            mockBookKeeper.reallyShutdown();
        }
        if (mockZooKeeper != null) {
            mockZooKeeper.shutdown();
        }
        if (orderedExecutorList.size() > 0) {
            for (int i = 0; i < orderedExecutorList.size(); i++) {
                SameThreadOrderedSafeExecutor sameThreadOrderedSafeExecutor = orderedExecutorList.get(i);
                if (sameThreadOrderedSafeExecutor != null) {
                    try {
                        sameThreadOrderedSafeExecutor.shutdownNow();
                        sameThreadOrderedSafeExecutor.awaitTermination(5, TimeUnit.SECONDS);
                    } catch (InterruptedException ex) {
                        log.error("sameThreadOrderedSafeExecutor shutdown had error", ex);
                        Thread.currentThread().interrupt();
                    }
                    orderedExecutorList.set(i, null);
                }
            }
        }
        if (bkExecutor != null) {
            try {
                bkExecutor.shutdownNow();
                bkExecutor.awaitTermination(5, TimeUnit.SECONDS);
            } catch (InterruptedException ex) {
                log.error("bkExecutor shutdown had error", ex);
                Thread.currentThread().interrupt();
            }
            bkExecutor = null;
        }
    } catch (Exception e) {
        log.warn("Failed to clean up mocked pulsar service:", e);
    }
}
Also used : PulsarService(org.apache.pulsar.broker.PulsarService) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException)

Aggregations

SameThreadOrderedSafeExecutor (org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor)17 PulsarService (org.apache.pulsar.broker.PulsarService)6 CounterBrokerInterceptor (org.apache.pulsar.broker.intercept.CounterBrokerInterceptor)6 ZKMetadataStore (org.apache.pulsar.metadata.impl.ZKMetadataStore)6 MockZooKeeperSession (org.apache.zookeeper.MockZooKeeperSession)6 URL (java.net.URL)4 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)3 MetadataStoreException (org.apache.pulsar.metadata.api.MetadataStoreException)2 SchemaRegistryRestApplication (io.confluent.kafka.schemaregistry.rest.SchemaRegistryRestApplication)1 URI (java.net.URI)1 Properties (java.util.Properties)1