Search in sources :

Example 6 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class PersistentTopicConcurrentTest method setup.

@BeforeMethod
public void setup(Method m) throws Exception {
    super.setUp(m);
    ServiceConfiguration svcConfig = spy(new ServiceConfiguration());
    PulsarService pulsar = spy(new PulsarService(svcConfig));
    doReturn(svcConfig).when(pulsar).getConfiguration();
    mlFactoryMock = mock(ManagedLedgerFactory.class);
    ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    final ManagedCursor cursor = ledger.openCursor("c1");
    cursorMock = cursor;
    ledgerMock = ledger;
    mlFactoryMock = factory;
    doReturn(mlFactoryMock).when(pulsar).getManagedLedgerFactory();
    ZooKeeper mockZk = mock(ZooKeeper.class);
    doReturn(mockZk).when(pulsar).getZkClient();
    brokerService = spy(new BrokerService(pulsar));
    doReturn(brokerService).when(pulsar).getBrokerService();
    serverCnx = spy(new ServerCnx(brokerService));
    doReturn(true).when(serverCnx).isActive();
    NamespaceService nsSvc = mock(NamespaceService.class);
    doReturn(nsSvc).when(pulsar).getNamespaceService();
    doReturn(true).when(nsSvc).isServiceUnitOwned(any(NamespaceBundle.class));
    doReturn(true).when(nsSvc).isServiceUnitActive(any(DestinationName.class));
    final List<Position> addedEntries = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        Position pos = ledger.addEntry("entry".getBytes());
        addedEntries.add(pos);
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ServerCnx(com.yahoo.pulsar.broker.service.ServerCnx) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) ZooKeeper(org.apache.zookeeper.ZooKeeper) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) NamespaceService(com.yahoo.pulsar.broker.namespace.NamespaceService) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) BrokerService(com.yahoo.pulsar.broker.service.BrokerService) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class HttpDestinationLookupv2Test method setUp.

@SuppressWarnings("unchecked")
@BeforeMethod
public void setUp() throws Exception {
    pulsar = mock(PulsarService.class);
    ns = mock(NamespaceService.class);
    auth = mock(AuthorizationManager.class);
    mockConfigCache = mock(ConfigurationCacheService.class);
    clustersListCache = mock(ZooKeeperChildrenCache.class);
    clustersCache = mock(ZooKeeperDataCache.class);
    policiesCache = mock(ZooKeeperDataCache.class);
    config = spy(new ServiceConfiguration());
    config.setClusterName("use");
    clusters = new TreeSet<String>();
    clusters.add("use");
    clusters.add("usc");
    clusters.add("usw");
    ClusterData useData = new ClusterData("http://broker.messaging.use.example.com:8080");
    ClusterData uscData = new ClusterData("http://broker.messaging.usc.example.com:8080");
    ClusterData uswData = new ClusterData("http://broker.messaging.usw.example.com:8080");
    doReturn(config).when(pulsar).getConfiguration();
    doReturn(mockConfigCache).when(pulsar).getConfigurationCache();
    doReturn(clustersListCache).when(mockConfigCache).clustersListCache();
    doReturn(clustersCache).when(mockConfigCache).clustersCache();
    doReturn(policiesCache).when(mockConfigCache).policiesCache();
    doReturn(Optional.of(useData)).when(clustersCache).get(AdminResource.path("clusters", "use"));
    doReturn(Optional.of(uscData)).when(clustersCache).get(AdminResource.path("clusters", "usc"));
    doReturn(Optional.of(uswData)).when(clustersCache).get(AdminResource.path("clusters", "usw"));
    doReturn(CompletableFuture.completedFuture(Optional.of(useData))).when(clustersCache).getAsync(AdminResource.path("clusters", "use"));
    doReturn(CompletableFuture.completedFuture(Optional.of(uscData))).when(clustersCache).getAsync(AdminResource.path("clusters", "usc"));
    doReturn(CompletableFuture.completedFuture(Optional.of(uswData))).when(clustersCache).getAsync(AdminResource.path("clusters", "usw"));
    doReturn(clusters).when(clustersListCache).get();
    doReturn(ns).when(pulsar).getNamespaceService();
    BrokerService brokerService = mock(BrokerService.class);
    doReturn(brokerService).when(pulsar).getBrokerService();
    doReturn(auth).when(brokerService).getAuthorizationManager();
    doReturn(new Semaphore(1000)).when(brokerService).getLookupRequestSemaphore();
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) PulsarService(com.yahoo.pulsar.broker.PulsarService) NamespaceService(com.yahoo.pulsar.broker.namespace.NamespaceService) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) ConfigurationCacheService(com.yahoo.pulsar.broker.cache.ConfigurationCacheService) ZooKeeperChildrenCache(com.yahoo.pulsar.zookeeper.ZooKeeperChildrenCache) AuthorizationManager(com.yahoo.pulsar.broker.authorization.AuthorizationManager) ZooKeeperDataCache(com.yahoo.pulsar.zookeeper.ZooKeeperDataCache) Semaphore(java.util.concurrent.Semaphore) BrokerService(com.yahoo.pulsar.broker.service.BrokerService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class LoadBalancerTest method setup.

@BeforeMethod
void setup() throws Exception {
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, PortManager.nextFreePort());
    bkEnsemble.start();
    ZkUtils.createFullPathOptimistic(bkEnsemble.getZkClient(), SimpleLoadManagerImpl.LOADBALANCER_DYNAMIC_SETTING_STRATEGY_ZPATH, "{\"loadBalancerStrategy\":\"leastLoadedServer\"}".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    // start brokers
    for (int i = 0; i < BROKER_COUNT; i++) {
        brokerWebServicePorts[i] = PortManager.nextFreePort();
        brokerNativeBrokerPorts[i] = PortManager.nextFreePort();
        ServiceConfiguration config = new ServiceConfiguration();
        config.setBrokerServicePort(brokerNativeBrokerPorts[i]);
        config.setClusterName("use");
        config.setWebServicePort(brokerWebServicePorts[i]);
        config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
        config.setBrokerServicePort(brokerNativeBrokerPorts[i]);
        pulsarServices[i] = new PulsarService(config);
        pulsarServices[i].start();
        brokerUrls[i] = new URL("http://127.0.0.1" + ":" + brokerWebServicePorts[i]);
        lookupAddresses[i] = pulsarServices[i].getAdvertisedAddress() + ":" + config.getWebServicePort();
        pulsarAdmins[i] = new PulsarAdmin(brokerUrls[i], (Authentication) null);
    }
    createNamespacePolicies(pulsarServices[0]);
    Thread.sleep(100);
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) Authentication(com.yahoo.pulsar.client.api.Authentication) LocalBookkeeperEnsemble(com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class BacklogQuotaManagerTest method setup.

@BeforeMethod
void setup() throws Exception {
    try {
        // start local bookie and zookeeper
        bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 5001);
        bkEnsemble.start();
        // start pulsar service
        config = new ServiceConfiguration();
        config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
        config.setWebServicePort(BROKER_WEBSERVICE_PORT);
        config.setClusterName("usc");
        config.setBrokerServicePort(BROKER_SERVICE_PORT);
        config.setAuthorizationEnabled(false);
        config.setAuthenticationEnabled(false);
        config.setBacklogQuotaCheckIntervalInSeconds(TIME_TO_CHECK_BACKLOG_QUOTA);
        config.setManagedLedgerMaxEntriesPerLedger(5);
        config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
        pulsar = new PulsarService(config);
        pulsar.start();
        adminUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
        admin = new PulsarAdmin(adminUrl, (Authentication) null);
        admin.clusters().createCluster("usc", new ClusterData(adminUrl.toString()));
        admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("usc")));
        admin.namespaces().createNamespace("prop/usc/ns-quota");
        admin.namespaces().createNamespace("prop/usc/quotahold");
        admin.namespaces().createNamespace("prop/usc/quotaholdasync");
    } catch (Throwable t) {
        LOG.error("Error setting up broker test", t);
        Assert.fail("Broker test setup failed");
    }
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) Authentication(com.yahoo.pulsar.client.api.Authentication) LocalBookkeeperEnsemble(com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 10 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

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 = mock(ZooKeeper.class);
    doReturn(mockZk).when(pulsar).getZkClient();
    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());
    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(DestinationName.class));
    setupMLAsyncCallbackMocks();
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) Policies(com.yahoo.pulsar.common.policies.data.Policies) InetSocketAddress(java.net.InetSocketAddress) ZooKeeper(org.apache.zookeeper.ZooKeeper) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) NamespaceService(com.yahoo.pulsar.broker.namespace.NamespaceService) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ConfigurationCacheService(com.yahoo.pulsar.broker.cache.ConfigurationCacheService) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)36 PulsarService (com.yahoo.pulsar.broker.PulsarService)18 Test (org.testng.annotations.Test)15 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)8 BeforeMethod (org.testng.annotations.BeforeMethod)8 AuthenticationService (com.yahoo.pulsar.broker.authentication.AuthenticationService)7 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)7 URL (java.net.URL)7 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)6 Authentication (com.yahoo.pulsar.client.api.Authentication)6 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)6 Field (java.lang.reflect.Field)6 ConfigurationCacheService (com.yahoo.pulsar.broker.cache.ConfigurationCacheService)5 NamespaceService (com.yahoo.pulsar.broker.namespace.NamespaceService)5 Policies (com.yahoo.pulsar.common.policies.data.Policies)5 LocalBookkeeperEnsemble (com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble)5 InetSocketAddress (java.net.InetSocketAddress)5 URI (java.net.URI)5 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)5 AuthorizationManager (com.yahoo.pulsar.broker.authorization.AuthorizationManager)4