Search in sources :

Example 1 with LocalZooKeeperCacheService

use of org.apache.pulsar.broker.cache.LocalZooKeeperCacheService in project incubator-pulsar by apache.

the class PulsarService method startZkCacheService.

private void startZkCacheService() throws PulsarServerException {
    LOG.info("starting configuration cache service");
    this.localZkCache = new LocalZooKeeperCache(getZkClient(), getOrderedExecutor(), this.cacheExecutor);
    this.globalZkCache = new GlobalZooKeeperCache(getZooKeeperClientFactory(), (int) config.getZooKeeperSessionTimeoutMillis(), config.getGlobalZookeeperServers(), getOrderedExecutor(), this.cacheExecutor);
    try {
        this.globalZkCache.start();
    } catch (IOException e) {
        throw new PulsarServerException(e);
    }
    this.configurationCacheService = new ConfigurationCacheService(getGlobalZkCache(), this.config.getClusterName());
    this.localZkCacheService = new LocalZooKeeperCacheService(getLocalZkCache(), this.configurationCacheService);
}
Also used : GlobalZooKeeperCache(org.apache.pulsar.zookeeper.GlobalZooKeeperCache) LocalZooKeeperCache(org.apache.pulsar.zookeeper.LocalZooKeeperCache) ConfigurationCacheService(org.apache.pulsar.broker.cache.ConfigurationCacheService) IOException(java.io.IOException) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService)

Example 2 with LocalZooKeeperCacheService

use of org.apache.pulsar.broker.cache.LocalZooKeeperCacheService in project incubator-pulsar by apache.

the class NamespaceBundlesTest method getNamespaceBundleFactory.

@SuppressWarnings("unchecked")
private NamespaceBundleFactory getNamespaceBundleFactory() {
    PulsarService pulsar = mock(PulsarService.class);
    LocalZooKeeperCacheService localZkCache = mock(LocalZooKeeperCacheService.class);
    ZooKeeperDataCache<LocalPolicies> poilciesCache = mock(ZooKeeperDataCache.class);
    when(pulsar.getLocalZkCacheService()).thenReturn(localZkCache);
    when(localZkCache.policiesCache()).thenReturn(poilciesCache);
    doNothing().when(poilciesCache).registerListener(any());
    return NamespaceBundleFactory.createFactory(pulsar, Hashing.crc32());
}
Also used : PulsarService(org.apache.pulsar.broker.PulsarService) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService)

Example 3 with LocalZooKeeperCacheService

use of org.apache.pulsar.broker.cache.LocalZooKeeperCacheService in project incubator-pulsar by apache.

the class PersistentDispatcherFailoverConsumerTest method setup.

@BeforeMethod
public void setup() throws Exception {
    ServiceConfiguration svcConfig = spy(new ServiceConfiguration());
    PulsarService pulsar = spy(new PulsarService(svcConfig));
    doReturn(svcConfig).when(pulsar).getConfiguration();
    mlFactoryMock = mock(ManagedLedgerFactory.class);
    doReturn(mlFactoryMock).when(pulsar).getManagedLedgerFactory();
    ZooKeeper mockZk = createMockZooKeeper();
    doReturn(mockZk).when(pulsar).getZkClient();
    doReturn(createMockBookKeeper(mockZk)).when(pulsar).getBookKeeperClient();
    configCacheService = mock(ConfigurationCacheService.class);
    @SuppressWarnings("unchecked") ZooKeeperDataCache<Policies> zkDataCache = mock(ZooKeeperDataCache.class);
    LocalZooKeeperCacheService zkCache = mock(LocalZooKeeperCacheService.class);
    doReturn(CompletableFuture.completedFuture(Optional.empty())).when(zkDataCache).getAsync(any());
    doReturn(zkDataCache).when(zkCache).policiesCache();
    doReturn(zkDataCache).when(configCacheService).policiesCache();
    doReturn(configCacheService).when(pulsar).getConfigurationCache();
    doReturn(zkCache).when(pulsar).getLocalZkCacheService();
    brokerService = spy(new BrokerService(pulsar));
    doReturn(brokerService).when(pulsar).getBrokerService();
    consumerChanges = new LinkedBlockingQueue<>();
    this.channelCtx = mock(ChannelHandlerContext.class);
    doAnswer(invocationOnMock -> {
        ByteBuf buf = invocationOnMock.getArgumentAt(0, ByteBuf.class);
        ByteBuf cmdBuf = buf.retainedSlice(4, buf.writerIndex() - 4);
        try {
            int cmdSize = (int) cmdBuf.readUnsignedInt();
            int writerIndex = cmdBuf.writerIndex();
            cmdBuf.writerIndex(cmdBuf.readerIndex() + cmdSize);
            ByteBufCodedInputStream cmdInputStream = ByteBufCodedInputStream.get(cmdBuf);
            BaseCommand.Builder cmdBuilder = BaseCommand.newBuilder();
            BaseCommand cmd = cmdBuilder.mergeFrom(cmdInputStream, null).build();
            cmdBuilder.recycle();
            cmdBuf.writerIndex(writerIndex);
            cmdInputStream.recycle();
            if (cmd.hasActiveConsumerChange()) {
                consumerChanges.put(cmd.getActiveConsumerChange());
            }
            cmd.recycle();
        } finally {
            cmdBuf.release();
        }
        return null;
    }).when(channelCtx).writeAndFlush(any(), any());
    serverCnx = spy(new ServerCnx(brokerService));
    doReturn(true).when(serverCnx).isActive();
    doReturn(true).when(serverCnx).isWritable();
    doReturn(new InetSocketAddress("localhost", 1234)).when(serverCnx).clientAddress();
    when(serverCnx.getRemoteEndpointProtocolVersion()).thenReturn(ProtocolVersion.v12.getNumber());
    when(serverCnx.ctx()).thenReturn(channelCtx);
    serverCnxWithOldVersion = spy(new ServerCnx(brokerService));
    doReturn(true).when(serverCnxWithOldVersion).isActive();
    doReturn(true).when(serverCnxWithOldVersion).isWritable();
    doReturn(new InetSocketAddress("localhost", 1234)).when(serverCnxWithOldVersion).clientAddress();
    when(serverCnxWithOldVersion.getRemoteEndpointProtocolVersion()).thenReturn(ProtocolVersion.v11.getNumber());
    when(serverCnxWithOldVersion.ctx()).thenReturn(channelCtx);
    NamespaceService nsSvc = mock(NamespaceService.class);
    doReturn(nsSvc).when(pulsar).getNamespaceService();
    doReturn(true).when(nsSvc).isServiceUnitOwned(any(NamespaceBundle.class));
    doReturn(true).when(nsSvc).isServiceUnitActive(any(TopicName.class));
    setupMLAsyncCallbackMocks();
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Policies(org.apache.pulsar.common.policies.data.Policies) BaseCommand(org.apache.pulsar.common.api.proto.PulsarApi.BaseCommand) InetSocketAddress(java.net.InetSocketAddress) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) TopicName(org.apache.pulsar.common.naming.TopicName) ZooKeeper(org.apache.zookeeper.ZooKeeper) MockedPulsarServiceBaseTest.createMockZooKeeper(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ConfigurationCacheService(org.apache.pulsar.broker.cache.ConfigurationCacheService) ByteBufCodedInputStream(org.apache.pulsar.common.util.protobuf.ByteBufCodedInputStream) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with LocalZooKeeperCacheService

use of org.apache.pulsar.broker.cache.LocalZooKeeperCacheService in project incubator-pulsar by apache.

the class PersistentTopicTest method setup.

@BeforeMethod
public void setup() throws Exception {
    ServiceConfiguration svcConfig = spy(new ServiceConfiguration());
    pulsar = spy(new PulsarService(svcConfig));
    doReturn(svcConfig).when(pulsar).getConfiguration();
    mlFactoryMock = mock(ManagedLedgerFactory.class);
    doReturn(mlFactoryMock).when(pulsar).getManagedLedgerFactory();
    ZooKeeper mockZk = createMockZooKeeper();
    doReturn(mockZk).when(pulsar).getZkClient();
    doReturn(createMockBookKeeper(mockZk)).when(pulsar).getBookKeeperClient();
    configCacheService = mock(ConfigurationCacheService.class);
    @SuppressWarnings("unchecked") ZooKeeperDataCache<Policies> zkDataCache = mock(ZooKeeperDataCache.class);
    doReturn(zkDataCache).when(configCacheService).policiesCache();
    doReturn(configCacheService).when(pulsar).getConfigurationCache();
    doReturn(Optional.empty()).when(zkDataCache).get(anyString());
    LocalZooKeeperCacheService zkCache = mock(LocalZooKeeperCacheService.class);
    doReturn(CompletableFuture.completedFuture(Optional.empty())).when(zkDataCache).getAsync(any());
    doReturn(zkDataCache).when(zkCache).policiesCache();
    doReturn(configCacheService).when(pulsar).getConfigurationCache();
    doReturn(zkCache).when(pulsar).getLocalZkCacheService();
    brokerService = spy(new BrokerService(pulsar));
    doReturn(brokerService).when(pulsar).getBrokerService();
    serverCnx = spy(new ServerCnx(brokerService));
    doReturn(true).when(serverCnx).isActive();
    doReturn(true).when(serverCnx).isWritable();
    doReturn(new InetSocketAddress("localhost", 1234)).when(serverCnx).clientAddress();
    NamespaceService nsSvc = mock(NamespaceService.class);
    doReturn(nsSvc).when(pulsar).getNamespaceService();
    doReturn(true).when(nsSvc).isServiceUnitOwned(any(NamespaceBundle.class));
    doReturn(true).when(nsSvc).isServiceUnitActive(any(TopicName.class));
    setupMLAsyncCallbackMocks();
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Policies(org.apache.pulsar.common.policies.data.Policies) InetSocketAddress(java.net.InetSocketAddress) TopicName(org.apache.pulsar.common.naming.TopicName) ZooKeeper(org.apache.zookeeper.ZooKeeper) MockedPulsarServiceBaseTest.createMockZooKeeper(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ConfigurationCacheService(org.apache.pulsar.broker.cache.ConfigurationCacheService) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with LocalZooKeeperCacheService

use of org.apache.pulsar.broker.cache.LocalZooKeeperCacheService in project incubator-pulsar by apache.

the class OwnershipCacheTest method setup.

@BeforeMethod
public void setup() throws Exception {
    final int port = 8080;
    selfBrokerUrl = "tcp://localhost:" + port;
    pulsar = mock(PulsarService.class);
    config = mock(ServiceConfiguration.class);
    executor = OrderedScheduler.newSchedulerBuilder().numThreads(1).name("test").build();
    scheduledExecutor = Executors.newScheduledThreadPool(2);
    zkCache = new LocalZooKeeperCache(MockZooKeeper.newInstance(), executor, scheduledExecutor);
    localCache = spy(new LocalZooKeeperCacheService(zkCache, null));
    ZooKeeperDataCache<LocalPolicies> poilciesCache = mock(ZooKeeperDataCache.class);
    when(pulsar.getLocalZkCacheService()).thenReturn(localCache);
    when(localCache.policiesCache()).thenReturn(poilciesCache);
    doNothing().when(poilciesCache).registerListener(any());
    bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
    nsService = mock(NamespaceService.class);
    brokerService = mock(BrokerService.class);
    doReturn(CompletableFuture.completedFuture(1)).when(brokerService).unloadServiceUnit(anyObject());
    doReturn(zkCache).when(pulsar).getLocalZkCache();
    doReturn(localCache).when(pulsar).getLocalZkCacheService();
    doReturn(config).when(pulsar).getConfiguration();
    doReturn(nsService).when(pulsar).getNamespaceService();
    doReturn(port).when(config).getBrokerServicePort();
    doReturn(brokerService).when(pulsar).getBrokerService();
    doReturn(webAddress(config)).when(pulsar).getWebServiceAddress();
    doReturn(selfBrokerUrl).when(pulsar).getBrokerServiceUrl();
}
Also used : PulsarService(org.apache.pulsar.broker.PulsarService) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) LocalZooKeeperCache(org.apache.pulsar.zookeeper.LocalZooKeeperCache) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) BrokerService(org.apache.pulsar.broker.service.BrokerService) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

LocalZooKeeperCacheService (org.apache.pulsar.broker.cache.LocalZooKeeperCacheService)7 PulsarService (org.apache.pulsar.broker.PulsarService)6 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)4 ConfigurationCacheService (org.apache.pulsar.broker.cache.ConfigurationCacheService)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)3 MockedPulsarServiceBaseTest.createMockZooKeeper (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper)3 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)3 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)3 TopicName (org.apache.pulsar.common.naming.TopicName)3 LocalPolicies (org.apache.pulsar.common.policies.data.LocalPolicies)3 Policies (org.apache.pulsar.common.policies.data.Policies)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 InetSocketAddress (java.net.InetSocketAddress)2 LocalZooKeeperCache (org.apache.pulsar.zookeeper.LocalZooKeeperCache)2 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 IOException (java.io.IOException)1 BrokerService (org.apache.pulsar.broker.service.BrokerService)1 DefaultSchemaRegistryService (org.apache.pulsar.broker.service.schema.DefaultSchemaRegistryService)1