@Test public void testZkHierarchyDepth() { AssertExtensions.assertThrows("BookKeeperConfig did not throw InvalidPropertyValueException", () -> BookKeeperConfig.builder() .with(BookKeeperConfig.ZK_HIERARCHY_DEPTH, -1) .build(), ex -> ex instanceof InvalidPropertyValueException); } }
.builder() .with(BookKeeperConfig.ZK_ADDRESS, "localhost:" + BK_PORT.get()) .with(BookKeeperConfig.MAX_WRITE_ATTEMPTS, MAX_WRITE_ATTEMPTS)
@Test public void testQuorumSize() { AssertExtensions.assertThrows("BookKeeperConfig did not throw InvalidPropertyValueException", () -> BookKeeperConfig.builder() .with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, 3) .with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, 2) .build(), ex -> ex instanceof InvalidPropertyValueException); }
/** * Tests the BookKeeperLogFactory and its initialization. */ @Test public void testFactoryInitialize() { BookKeeperConfig bkConfig = BookKeeperConfig .builder() .with(BookKeeperConfig.ZK_ADDRESS, "localhost:" + BK_PORT.get()) .with(BookKeeperConfig.BK_LEDGER_MAX_SIZE, WRITE_MAX_LENGTH * 10) // Very frequent rollovers. .with(BookKeeperConfig.ZK_METADATA_PATH, this.zkClient.get().getNamespace()) .build(); @Cleanup val factory = new BookKeeperLogFactory(bkConfig, this.zkClient.get(), executorService()); AssertExtensions.assertThrows("", factory::initialize, ex -> ex instanceof DataLogNotAvailableException && ex.getCause() instanceof BKException.ZKException ); }
@Test public void testZkServers() { // When multiple servers are specified and separated by comma, it should replace it by semicolon BookKeeperConfig cfg1 = BookKeeperConfig.builder() .with(BookKeeperConfig.ZK_ADDRESS, "foo:12345,bar:54321") .build(); Assert.assertEquals("foo:12345;bar:54321", cfg1.getZkAddress()); // No changes should be made to the following configs BookKeeperConfig cfg2 = BookKeeperConfig.builder() .with(BookKeeperConfig.ZK_ADDRESS, "foo:12345") .build(); Assert.assertEquals("foo:12345", cfg2.getZkAddress()); BookKeeperConfig cfg3 = BookKeeperConfig.builder() .with(BookKeeperConfig.ZK_ADDRESS, "10.20.30.40:12345;bar:2181") .build(); Assert.assertEquals("10.20.30.40:12345;bar:2181", cfg3.getZkAddress()); }
b.include(ServiceConfig.builder() .with(ServiceConfig.CONTAINER_COUNT, testConfig.getContainerCount())); b.include(BookKeeperConfig.builder() .with(BookKeeperConfig.ZK_ADDRESS, TestConfig.LOCALHOST + ":" + testConfig.getZkPort()) .with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, bkWriteQuorum)
.builder() .with(BookKeeperConfig.ZK_ADDRESS, "localhost:" + zkPort) .with(BookKeeperConfig.ZK_METADATA_PATH, logMetaNamespace)
/** * Creates a new Context to be used by the BookKeeper command. * * @return A new Context. * @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized. */ protected Context createContext() throws DurableDataLogException { val serviceConfig = getServiceConfig(); val bkConfig = getCommandArgs().getState().getConfigBuilder() .include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())) .build().getConfig(BookKeeperConfig::builder); val zkClient = createZKClient(); val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor()); try { factory.initialize(); } catch (DurableDataLogException ex) { zkClient.close(); throw ex; } val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient()); return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin); }
/** * Creates a new Context to be used by the BookKeeper command. * * @return A new Context. * @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized. */ @Override protected Context createContext() throws DurableDataLogException { val serviceConfig = getServiceConfig(); val containerConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ContainerConfig::builder); val bkConfig = getCommandArgs().getState().getConfigBuilder() .include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())) .build().getConfig(BookKeeperConfig::builder); val zkClient = createZKClient(); val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor()); try { factory.initialize(); } catch (DurableDataLogException ex) { zkClient.close(); throw ex; } val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient()); return new Context(serviceConfig, containerConfig, bkConfig, zkClient, factory, bkAdmin); }
/** * Generates a new ServiceBuilderConfig.Builder with hardcoded defaults, in case these are not supplied via other means, * such as a config file or System Properties. */ private static ServiceBuilderConfig.Builder getDefaultServiceBuilderConfig() { return ServiceBuilderConfig .builder() .include(ServiceConfig.builder() .with(ServiceConfig.THREAD_POOL_SIZE, 80) .with(ServiceConfig.CACHE_POLICY_MAX_TIME, 600) .with(ServiceConfig.CACHE_POLICY_MAX_SIZE, 4 * 1024 * 1024 * 1024L) .with(ServiceConfig.CERT_FILE, "../config/cert.pem") .with(ServiceConfig.KEY_FILE, "../config/key.pem")) .include(DurableLogConfig.builder() .with(DurableLogConfig.CHECKPOINT_COMMIT_COUNT, 100) .with(DurableLogConfig.CHECKPOINT_MIN_COMMIT_COUNT, 100) .with(DurableLogConfig.CHECKPOINT_TOTAL_COMMIT_LENGTH, 100 * 1024 * 1024L)) .include(ReadIndexConfig.builder() .with(ReadIndexConfig.MEMORY_READ_MIN_LENGTH, 128 * 1024)) .include(ContainerConfig.builder() .with(ContainerConfig.SEGMENT_METADATA_EXPIRATION_SECONDS, ContainerConfig.MINIMUM_SEGMENT_METADATA_EXPIRATION_SECONDS) .with(ContainerConfig.MAX_ACTIVE_SEGMENT_COUNT, 500)) // This is for those tests that use BookKeeper for Tier1. .include(BookKeeperConfig.builder() .with(BookKeeperConfig.BK_LEDGER_MAX_SIZE, Integer.MAX_VALUE) .with(BookKeeperConfig.ZK_METADATA_PATH, "/pravega/selftest/segmentstore/containers") .with(BookKeeperConfig.BK_LEDGER_PATH, TestConfig.BK_LEDGER_PATH)); }
@Test public void testDefaultValues() { BookKeeperConfig cfg = BookKeeperConfig.builder() .build(); Assert.assertEquals("localhost:2181", cfg.getZkAddress()); Assert.assertEquals(Duration.ofMillis(10000), cfg.getZkSessionTimeout()); Assert.assertEquals(Duration.ofMillis(10000), cfg.getZkConnectionTimeout()); Assert.assertEquals("/segmentstore/containers", cfg.getZkMetadataPath()); Assert.assertEquals(2, cfg.getZkHierarchyDepth()); Assert.assertEquals(5, cfg.getMaxWriteAttempts()); Assert.assertEquals(3, cfg.getBkEnsembleSize()); Assert.assertEquals(2, cfg.getBkAckQuorumSize()); Assert.assertEquals(3, cfg.getBkWriteQuorumSize()); Assert.assertEquals(5000, cfg.getBkWriteTimeoutMillis()); Assert.assertEquals(5000, cfg.getBkReadTimeoutMillis()); Assert.assertEquals(1024 * 1024 * 1024, cfg.getBkLedgerMaxSize()); Assert.assertEquals(0, cfg.getBKPassword().length); Assert.assertEquals("", cfg.getBkLedgerPath()); Assert.assertEquals(false, cfg.isTLSEnabled()); Assert.assertEquals("config/client.truststore.jks", cfg.getTlsTrustStore()); Assert.assertEquals("", cfg.getTlsTrustStorePasswordPath()); }