From d612f92c2127ee3b4f88f077a6ca0b6455a5a271 Mon Sep 17 00:00:00 2001 From: Eugene R Date: Sun, 3 Dec 2023 10:29:54 +0200 Subject: [PATCH] FMWK-271 Create new policies based on client default settings (#44) --- .../aerospike/jdbc/AerospikeConnection.java | 11 +++- .../jdbc/AerospikePreparedStatement.java | 3 +- .../jdbc/async/ScanQueryHandler.java | 10 +-- .../async/SecondaryIndexQueryHandler.java | 14 ++--- .../jdbc/model/DriverConfiguration.java | 62 +++++++++---------- .../jdbc/query/BaseQueryHandler.java | 2 +- .../jdbc/query/InsertQueryHandler.java | 15 ++--- .../aerospike/jdbc/query/PolicyBuilder.java | 37 ++++++----- .../jdbc/query/SelectQueryHandler.java | 8 +-- .../jdbc/schema/AerospikeSchemaBuilder.java | 5 +- .../com/aerospike/jdbc/sql/SimpleWrapper.java | 2 - .../java/com/aerospike/jdbc/JdbcBaseTest.java | 2 +- .../com/aerospike/jdbc/ParseJdbcUrlTest.java | 36 ++++++++--- 13 files changed, 109 insertions(+), 98 deletions(-) diff --git a/src/main/java/com/aerospike/jdbc/AerospikeConnection.java b/src/main/java/com/aerospike/jdbc/AerospikeConnection.java index a9d97ca..1f9bf02 100644 --- a/src/main/java/com/aerospike/jdbc/AerospikeConnection.java +++ b/src/main/java/com/aerospike/jdbc/AerospikeConnection.java @@ -1,6 +1,5 @@ package com.aerospike.jdbc; -import com.aerospike.client.AerospikeClient; import com.aerospike.client.IAerospikeClient; import com.aerospike.client.policy.Policy; import com.aerospike.jdbc.model.DriverConfiguration; @@ -41,10 +40,10 @@ public class AerospikeConnection implements Connection, SimpleWrapper { private volatile boolean closed; public AerospikeConnection(String url, Properties props) { + logger.info("Init AerospikeConnection"); this.url = url; config = new DriverConfiguration(props); - config.parse(url); - client = new AerospikeClient(config.getClientPolicy(), config.getHosts()); + client = config.parse(url); metadataBuilder = new DatabaseMetadataBuilder(config.getDriverPolicy()); schema.set(config.getSchema()); // namespace } @@ -296,6 +295,7 @@ public boolean isValid(int timeout) { @Override public void setClientInfo(String name, String value) { + logger.info(() -> format("Set client info: %s -> %s", name, value)); config.put(name, value); } @@ -311,6 +311,7 @@ public Properties getClientInfo() { @Override public void setClientInfo(Properties properties) { + logger.info(() -> format("Set client info: %s", properties)); config.putAll(properties); } @@ -359,4 +360,8 @@ public int getNetworkTimeout() { public DriverConfiguration getConfiguration() { return config; } + + public IAerospikeClient getClient() { + return client; + } } diff --git a/src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java b/src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java index c37af1a..976c59d 100644 --- a/src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java +++ b/src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java @@ -49,8 +49,7 @@ public AerospikePreparedStatement(IAerospikeClient client, AerospikeConnection c } catch (SQLException e) { throw new UnsupportedOperationException(e); } - columns = AerospikeSchemaBuilder.getSchema(query.getSchemaTable(), client, - connection.getConfiguration().getScanPolicy()); + columns = AerospikeSchemaBuilder.getSchema(query.getSchemaTable(), client); } @Override diff --git a/src/main/java/com/aerospike/jdbc/async/ScanQueryHandler.java b/src/main/java/com/aerospike/jdbc/async/ScanQueryHandler.java index 4ff555f..2a6728e 100644 --- a/src/main/java/com/aerospike/jdbc/async/ScanQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/async/ScanQueryHandler.java @@ -8,7 +8,7 @@ import com.aerospike.client.policy.ScanPolicy; import com.aerospike.client.query.PartitionFilter; import com.aerospike.jdbc.model.AerospikeQuery; -import com.aerospike.jdbc.model.DriverConfiguration; +import com.aerospike.jdbc.model.DriverPolicy; import java.util.Objects; @@ -26,13 +26,13 @@ public class ScanQueryHandler { count++; }); - public ScanQueryHandler(IAerospikeClient client, DriverConfiguration config) { + public ScanQueryHandler(IAerospikeClient client, DriverPolicy driverPolicy) { this.client = client; - this.listener = new RecordSetRecordSequenceListener(config.getDriverPolicy()); + this.listener = new RecordSetRecordSequenceListener(driverPolicy); } - public static ScanQueryHandler create(IAerospikeClient client, DriverConfiguration config) { - return new ScanQueryHandler(client, config); + public static ScanQueryHandler create(IAerospikeClient client, DriverPolicy driverPolicy) { + return new ScanQueryHandler(client, driverPolicy); } public RecordSet execute(ScanPolicy scanPolicy, AerospikeQuery query) { diff --git a/src/main/java/com/aerospike/jdbc/async/SecondaryIndexQueryHandler.java b/src/main/java/com/aerospike/jdbc/async/SecondaryIndexQueryHandler.java index 429ca42..20db85d 100644 --- a/src/main/java/com/aerospike/jdbc/async/SecondaryIndexQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/async/SecondaryIndexQueryHandler.java @@ -4,7 +4,7 @@ import com.aerospike.client.policy.QueryPolicy; import com.aerospike.jdbc.model.AerospikeQuery; import com.aerospike.jdbc.model.AerospikeSecondaryIndex; -import com.aerospike.jdbc.model.DriverConfiguration; +import com.aerospike.jdbc.model.DriverPolicy; import java.util.Objects; import java.util.Optional; @@ -12,24 +12,22 @@ public class SecondaryIndexQueryHandler { private final IAerospikeClient client; - private final DriverConfiguration config; private final RecordSetRecordSequenceListener listener; - public SecondaryIndexQueryHandler(IAerospikeClient client, DriverConfiguration config) { + public SecondaryIndexQueryHandler(IAerospikeClient client, DriverPolicy driverPolicy) { this.client = client; - this.config = config; - this.listener = new RecordSetRecordSequenceListener(config.getDriverPolicy()); + this.listener = new RecordSetRecordSequenceListener(driverPolicy); } - public static SecondaryIndexQueryHandler create(IAerospikeClient client, DriverConfiguration config) { - return new SecondaryIndexQueryHandler(client, config); + public static SecondaryIndexQueryHandler create(IAerospikeClient client, DriverPolicy driverPolicy) { + return new SecondaryIndexQueryHandler(client, driverPolicy); } public RecordSet execute(QueryPolicy queryPolicy, AerospikeQuery query, AerospikeSecondaryIndex secondaryIndex) { com.aerospike.client.query.Statement statement = new com.aerospike.client.query.Statement(); Optional.ofNullable(query.getLimit()).ifPresent(statement::setMaxRecords); - statement.setRecordsPerSecond(config.getScanPolicy().recordsPerSecond); + statement.setRecordsPerSecond(client.getScanPolicyDefault().recordsPerSecond); statement.setIndexName(secondaryIndex.getIndexName()); statement.setNamespace(query.getSchema()); diff --git a/src/main/java/com/aerospike/jdbc/model/DriverConfiguration.java b/src/main/java/com/aerospike/jdbc/model/DriverConfiguration.java index ef05b70..5592eb9 100644 --- a/src/main/java/com/aerospike/jdbc/model/DriverConfiguration.java +++ b/src/main/java/com/aerospike/jdbc/model/DriverConfiguration.java @@ -1,13 +1,12 @@ package com.aerospike.jdbc.model; +import com.aerospike.client.AerospikeClient; import com.aerospike.client.Host; +import com.aerospike.client.IAerospikeClient; import com.aerospike.client.Value; import com.aerospike.client.policy.AuthMode; import com.aerospike.client.policy.ClientPolicy; -import com.aerospike.client.policy.QueryPolicy; -import com.aerospike.client.policy.ScanPolicy; import com.aerospike.client.policy.TlsPolicy; -import com.aerospike.client.policy.WritePolicy; import com.aerospike.jdbc.async.EventLoopProvider; import com.aerospike.jdbc.tls.AerospikeTLSPolicyBuilder; import com.aerospike.jdbc.tls.AerospikeTLSPolicyConfig; @@ -23,6 +22,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import static java.lang.String.format; +import static java.util.Objects.requireNonNull; + public final class DriverConfiguration { private static final Logger logger = Logger.getLogger(DriverConfiguration.class.getName()); @@ -33,30 +35,32 @@ public final class DriverConfiguration { private static final Pattern AS_JDBC_SCHEMA = Pattern.compile("/([^?]+)"); private final Map clientInfo = new ConcurrentHashMap<>(); - private volatile Host[] hosts; + private volatile IAerospikeClient client; private volatile String schema; private volatile ClientPolicy clientPolicy; - private volatile WritePolicy writePolicy; - private volatile ScanPolicy scanPolicy; - private volatile QueryPolicy queryPolicy; private volatile DriverPolicy driverPolicy; public DriverConfiguration(Properties props) { - logger.info(() -> "Configuration properties: " + props); + logger.info(() -> format("Init DriverConfiguration with properties: %s", props)); clientInfo.putAll(props); } @SuppressWarnings("java:S2696") - public void parse(String url) { + public IAerospikeClient parse(String url) { + logger.info(() -> format("Parse URL: %s", url)); schema = parseSchema(url); updateClientInfo(url); - hosts = parseHosts(url, Optional.ofNullable(clientInfo.get("tlsName")) - .map(Object::toString).orElse(null)); - clientPolicy = buildClientPolicy(); - resetPolicies(); + Value.UseBoolBin = Optional.ofNullable(clientInfo.get("useBoolBin")) .map(Object::toString).map(Boolean::parseBoolean).orElse(true); - logger.info(() -> "Value.UseBoolBin = " + Value.UseBoolBin); + logger.info(() -> format("Value.UseBoolBin = %b", Value.UseBoolBin)); + + clientPolicy = buildClientPolicy(); + Host[] hosts = parseHosts(url, Optional.ofNullable(clientInfo.get("tlsName")) + .map(Object::toString).orElse(null)); + client = new AerospikeClient(clientPolicy, hosts); + resetPolicies(); + return client; } private ClientPolicy buildClientPolicy() { @@ -67,9 +71,15 @@ private ClientPolicy buildClientPolicy() { } private void resetPolicies() { - writePolicy = copy(new WritePolicy()); - scanPolicy = copy(new ScanPolicy()); - queryPolicy = copy(new QueryPolicy()); + logger.fine(() -> "resetPolicies call"); + if (client != null) { + copy(client.getReadPolicyDefault()); + copy(client.getWritePolicyDefault()); + copy(client.getScanPolicyDefault()); + copy(client.getQueryPolicyDefault()); + copy(client.getBatchPolicyDefault()); + copy(client.getInfoPolicyDefault()); + } driverPolicy = new DriverPolicy(getClientInfo()); } @@ -131,10 +141,6 @@ private void updateClientInfo(String url) { } } - public Host[] getHosts() { - return hosts; - } - public String getSchema() { return schema; } @@ -156,22 +162,12 @@ public void putAll(Properties properties) { } public ClientPolicy getClientPolicy() { + requireNonNull(clientPolicy, "clientPolicy is null"); return clientPolicy; } - public WritePolicy getWritePolicy() { - return writePolicy; - } - - public ScanPolicy getScanPolicy() { - return scanPolicy; - } - - public QueryPolicy getQueryPolicy() { - return queryPolicy; - } - public DriverPolicy getDriverPolicy() { + requireNonNull(driverPolicy, "driverPolicy is null"); return driverPolicy; } } diff --git a/src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java index a52aec3..6edd395 100644 --- a/src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java @@ -29,7 +29,7 @@ protected BaseQueryHandler(IAerospikeClient client, Statement statement) { } catch (SQLException e) { throw new IllegalStateException("Failed to get configuration", e); } - policyBuilder = new PolicyBuilder(config); + policyBuilder = new PolicyBuilder(client); } protected Bin[] getBins(AerospikeQuery query) { diff --git a/src/main/java/com/aerospike/jdbc/query/InsertQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/InsertQueryHandler.java index 888e0f9..8d00da9 100644 --- a/src/main/java/com/aerospike/jdbc/query/InsertQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/InsertQueryHandler.java @@ -3,7 +3,6 @@ import com.aerospike.client.*; import com.aerospike.client.policy.BatchPolicy; import com.aerospike.client.policy.BatchWritePolicy; -import com.aerospike.client.policy.RecordExistsAction; import com.aerospike.client.policy.WritePolicy; import com.aerospike.jdbc.async.EventLoopProvider; import com.aerospike.jdbc.async.FutureBatchOperateListListener; @@ -75,10 +74,7 @@ public Pair putBatch(AerospikeQuery query) { FutureBatchOperateListListener listener = new FutureBatchOperateListListener(); List batchRecords = new ArrayList<>(); - - BatchWritePolicy batchWritePolicy = new BatchWritePolicy(); - batchWritePolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; - batchWritePolicy.sendKey = true; + BatchWritePolicy batchWritePolicy = policyBuilder.buildBatchCreateOnlyPolicy(); for (Object aerospikeRecord : query.getValues()) { @SuppressWarnings("unchecked") @@ -89,14 +85,13 @@ public Pair putBatch(AerospikeQuery query) { new BatchWrite( batchWritePolicy, key, - Arrays.stream(buildBinArray(binNames, values)).map(Operation::put).toArray(Operation[]::new) + Arrays.stream(buildBinArray(binNames, values)) + .map(Operation::put) + .toArray(Operation[]::new) ) ); } - BatchPolicy batchPolicy = new BatchPolicy(); - batchPolicy.sendKey = true; - batchPolicy.maxConcurrentThreads = batchRecords.size() / 100 + 1; - + BatchPolicy batchPolicy = client.getBatchPolicyDefault(); try { client.operate(EventLoopProvider.getEventLoop(), listener, batchPolicy, batchRecords); } catch (AerospikeException e) { diff --git a/src/main/java/com/aerospike/jdbc/query/PolicyBuilder.java b/src/main/java/com/aerospike/jdbc/query/PolicyBuilder.java index 4e9beb9..c850c5e 100644 --- a/src/main/java/com/aerospike/jdbc/query/PolicyBuilder.java +++ b/src/main/java/com/aerospike/jdbc/query/PolicyBuilder.java @@ -1,35 +1,35 @@ package com.aerospike.jdbc.query; +import com.aerospike.client.IAerospikeClient; import com.aerospike.client.exp.Exp; import com.aerospike.client.policy.BatchReadPolicy; +import com.aerospike.client.policy.BatchWritePolicy; import com.aerospike.client.policy.QueryPolicy; import com.aerospike.client.policy.RecordExistsAction; import com.aerospike.client.policy.ScanPolicy; import com.aerospike.client.policy.WritePolicy; import com.aerospike.jdbc.model.AerospikeQuery; -import com.aerospike.jdbc.model.DriverConfiguration; import java.util.Objects; public class PolicyBuilder { - protected final DriverConfiguration config; + protected final IAerospikeClient client; - public PolicyBuilder(DriverConfiguration config) { - this.config = config; + public PolicyBuilder(IAerospikeClient client) { + this.client = client; } public ScanPolicy buildScanPolicy(AerospikeQuery query) { - ScanPolicy scanPolicy = new ScanPolicy(config.getScanPolicy()); + ScanPolicy scanPolicy = new ScanPolicy(client.getScanPolicyDefault()); scanPolicy.maxRecords = Objects.isNull(query.getLimit()) ? 0 : query.getLimit(); scanPolicy.filterExp = Objects.isNull(query.getPredicate()) ? null : Exp.build(query.getPredicate().toFilterExpression()); - scanPolicy.sendKey = true; return scanPolicy; } public QueryPolicy buildQueryPolicy(AerospikeQuery query) { - QueryPolicy queryPolicy = new QueryPolicy(config.getQueryPolicy()); + QueryPolicy queryPolicy = new QueryPolicy(client.getQueryPolicyDefault()); queryPolicy.filterExp = Objects.isNull(query.getPredicate()) ? null : Exp.build(query.getPredicate().toFilterExpression()); return queryPolicy; @@ -42,30 +42,35 @@ public ScanPolicy buildScanNoBinDataPolicy(AerospikeQuery query) { } public WritePolicy buildWritePolicy(AerospikeQuery query) { - WritePolicy writePolicy = new WritePolicy(config.getWritePolicy()); + WritePolicy writePolicy = new WritePolicy(client.getWritePolicyDefault()); writePolicy.filterExp = Objects.isNull(query.getPredicate()) ? null : Exp.build(query.getPredicate().toFilterExpression()); - writePolicy.sendKey = true; return writePolicy; } public BatchReadPolicy buildBatchReadPolicy(AerospikeQuery query) { - BatchReadPolicy policy = new BatchReadPolicy(); - policy.filterExp = Objects.isNull(query.getPredicate()) + BatchReadPolicy batchReadPolicy = new BatchReadPolicy(); + batchReadPolicy.filterExp = Objects.isNull(query.getPredicate()) ? null : Exp.build(query.getPredicate().toFilterExpression()); - return policy; + return batchReadPolicy; + } + + public BatchWritePolicy buildBatchCreateOnlyPolicy() { + BatchWritePolicy batchWritePolicy = new BatchWritePolicy(); + batchWritePolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; + batchWritePolicy.sendKey = client.getBatchPolicyDefault().sendKey; + batchWritePolicy.expiration = client.getBatchWritePolicyDefault().expiration; + return batchWritePolicy; } public WritePolicy buildCreateOnlyPolicy() { - WritePolicy writePolicy = new WritePolicy(config.getWritePolicy()); - writePolicy.sendKey = true; + WritePolicy writePolicy = new WritePolicy(client.getWritePolicyDefault()); writePolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; return writePolicy; } public WritePolicy buildUpdateOnlyPolicy() { - WritePolicy writePolicy = new WritePolicy(config.getWritePolicy()); - writePolicy.sendKey = true; + WritePolicy writePolicy = new WritePolicy(client.getWritePolicyDefault()); writePolicy.recordExistsAction = RecordExistsAction.UPDATE_ONLY; return writePolicy; } diff --git a/src/main/java/com/aerospike/jdbc/query/SelectQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/SelectQueryHandler.java index 6877dfd..9e67b08 100644 --- a/src/main/java/com/aerospike/jdbc/query/SelectQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/SelectQueryHandler.java @@ -52,7 +52,7 @@ public SelectQueryHandler(IAerospikeClient client, Statement statement) { @Override public Pair execute(AerospikeQuery query) { - columns = AerospikeSchemaBuilder.getSchema(query.getSchemaTable(), client, config.getScanPolicy()); + columns = AerospikeSchemaBuilder.getSchema(query.getSchemaTable(), client); Collection keyObjects = query.getPrimaryKeys(); Optional sIndex = secondaryIndex(query); Pair result; @@ -75,7 +75,7 @@ private Pair executeCountQuery(AerospikeQuery query) { recordNumber = getTableRecordsNumber(client, query.getSchema(), query.getTable()); } else { ScanPolicy policy = policyBuilder.buildScanNoBinDataPolicy(query); - RecordSet recordSet = ScanQueryHandler.create(client, config).execute(policy, query); + RecordSet recordSet = ScanQueryHandler.create(client, config.getDriverPolicy()).execute(policy, query); final AtomicInteger count = new AtomicInteger(); recordSet.forEach(r -> count.incrementAndGet()); @@ -113,7 +113,7 @@ private Pair executeScan(AerospikeQuery query) { logger.info(() -> "SELECT scan " + (Objects.nonNull(query.getOffset()) ? "partition" : "all")); ScanPolicy policy = policyBuilder.buildScanPolicy(query); - RecordSet recordSet = ScanQueryHandler.create(client, config).execute(policy, query); + RecordSet recordSet = ScanQueryHandler.create(client, config.getDriverPolicy()).execute(policy, query); return new Pair<>(new AerospikeRecordResultSet(recordSet, statement, query.getSchema(), query.getTable(), filterColumns(columns, query.getBinNames())), -1); @@ -124,7 +124,7 @@ private Pair executeQuery(AerospikeQuery query, logger.info(() -> "SELECT secondary index query for column: " + secondaryIndex.getBinName()); QueryPolicy policy = policyBuilder.buildQueryPolicy(query); - RecordSet recordSet = SecondaryIndexQueryHandler.create(client, config) + RecordSet recordSet = SecondaryIndexQueryHandler.create(client, config.getDriverPolicy()) .execute(policy, query, secondaryIndex); return new Pair<>(new AerospikeRecordResultSet(recordSet, statement, query.getSchema(), diff --git a/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaBuilder.java b/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaBuilder.java index 7b46503..4bd8204 100644 --- a/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaBuilder.java +++ b/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaBuilder.java @@ -33,12 +33,11 @@ public static void cleanSchemaCache() { cache.clear(); } - public static List getSchema(SchemaTableName schemaTableName, IAerospikeClient client, - ScanPolicy scanPolicy) { + public static List getSchema(SchemaTableName schemaTableName, IAerospikeClient client) { return cache.get(schemaTableName).orElseGet(() -> { logger.info(() -> "Fetching SchemaTableName: " + schemaTableName); final Map columnHandles = new TreeMap<>(String::compareToIgnoreCase); - ScanPolicy policy = new ScanPolicy(scanPolicy); + ScanPolicy policy = new ScanPolicy(client.getScanPolicyDefault()); policy.maxRecords = schemaScanRecords; // add record key column handler diff --git a/src/main/java/com/aerospike/jdbc/sql/SimpleWrapper.java b/src/main/java/com/aerospike/jdbc/sql/SimpleWrapper.java index 5d1ad29..cc8f91e 100644 --- a/src/main/java/com/aerospike/jdbc/sql/SimpleWrapper.java +++ b/src/main/java/com/aerospike/jdbc/sql/SimpleWrapper.java @@ -7,7 +7,6 @@ public interface SimpleWrapper extends Wrapper { @Override default T unwrap(Class iface) throws SQLException { - // The implementation is taken from MySQL driver try { // This works for classes that aren't actually wrapping anything return iface.cast(this); @@ -18,7 +17,6 @@ default T unwrap(Class iface) throws SQLException { @Override default boolean isWrapperFor(Class iface) { - // The implementation is taken from MySQL driver // This works for classes that aren't actually wrapping anything return iface.isInstance(this); } diff --git a/src/test/java/com/aerospike/jdbc/JdbcBaseTest.java b/src/test/java/com/aerospike/jdbc/JdbcBaseTest.java index 03886d0..476972f 100644 --- a/src/test/java/com/aerospike/jdbc/JdbcBaseTest.java +++ b/src/test/java/com/aerospike/jdbc/JdbcBaseTest.java @@ -23,7 +23,7 @@ public abstract class JdbcBaseTest { public static void connectionInit() throws Exception { logger.info("connectionInit"); Class.forName("com.aerospike.jdbc.AerospikeDriver").newInstance(); - String url = String.format("jdbc:aerospike:%s:%d/%s", hostname, port, namespace); + String url = String.format("jdbc:aerospike:%s:%d/%s?sendKey=true", hostname, port, namespace); connection = DriverManager.getConnection(url); } diff --git a/src/test/java/com/aerospike/jdbc/ParseJdbcUrlTest.java b/src/test/java/com/aerospike/jdbc/ParseJdbcUrlTest.java index 8529e36..b20d0c4 100644 --- a/src/test/java/com/aerospike/jdbc/ParseJdbcUrlTest.java +++ b/src/test/java/com/aerospike/jdbc/ParseJdbcUrlTest.java @@ -1,5 +1,6 @@ package com.aerospike.jdbc; +import com.aerospike.client.IAerospikeClient; import com.aerospike.client.Value; import com.aerospike.client.policy.AuthMode; import com.aerospike.jdbc.model.DriverConfiguration; @@ -29,6 +30,7 @@ public void testParseUrlParameters() throws Exception { ); AerospikeConnection connection = (AerospikeConnection) DriverManager.getConnection(url); Properties properties = connection.getClientInfo(); + IAerospikeClient client = connection.getClient(); assertEquals(properties.getProperty("timeout"), "512"); assertEquals(properties.getProperty("totalTimeout"), "2000"); @@ -39,31 +41,45 @@ public void testParseUrlParameters() throws Exception { DriverConfiguration config = connection.getConfiguration(); assertEquals(config.getClientPolicy().timeout, 512); - assertEquals(config.getQueryPolicy().totalTimeout, 2000); - assertEquals(config.getWritePolicy().totalTimeout, 2000); - assertEquals(config.getScanPolicy().totalTimeout, 2000); + assertEquals(client.getInfoPolicyDefault().timeout, 512); + assertEquals(client.getScanPolicyDefault().recordsPerSecond, 0); + assertTotalTimeoutAll(client, 2000); + assertSendKeyAll(client, false); assertTrue(config.getClientPolicy().useServicesAlternate); assertEquals(config.getClientPolicy().authMode, AuthMode.EXTERNAL_INSECURE); assertEquals(config.getDriverPolicy().getRecordSetTimeoutMs(), 5000); assertFalse(Value.UseBoolBin); - assertFalse(config.getQueryPolicy().sendKey); Properties update = new Properties(); update.setProperty("totalTimeout", "3000"); update.setProperty("sendKey", "true"); update.setProperty("recordSetQueueCapacity", "1024"); update.setProperty("metadataCacheTtlSeconds", "7200"); + update.setProperty("recordsPerSecond", "128"); connection.setClientInfo(update); - assertEquals(config.getQueryPolicy().totalTimeout, 3000); - assertEquals(config.getWritePolicy().totalTimeout, 3000); - assertEquals(config.getScanPolicy().totalTimeout, 3000); - assertTrue(config.getQueryPolicy().sendKey); - assertTrue(config.getWritePolicy().sendKey); - assertTrue(config.getScanPolicy().sendKey); + assertEquals(client.getScanPolicyDefault().recordsPerSecond, 128); + assertTotalTimeoutAll(client, 3000); + assertSendKeyAll(client, true); assertEquals(config.getDriverPolicy().getRecordSetQueueCapacity(), 1024); assertEquals(config.getDriverPolicy().getMetadataCacheTtlSeconds(), 7200); connection.setClientInfo("recordSetTimeoutMs", "7000"); assertEquals(config.getDriverPolicy().getRecordSetTimeoutMs(), 7000); } + + private void assertTotalTimeoutAll(IAerospikeClient client, int timeout) { + assertEquals(client.getReadPolicyDefault().totalTimeout, timeout); + assertEquals(client.getWritePolicyDefault().totalTimeout, timeout); + assertEquals(client.getQueryPolicyDefault().totalTimeout, timeout); + assertEquals(client.getScanPolicyDefault().totalTimeout, timeout); + assertEquals(client.getBatchPolicyDefault().totalTimeout, timeout); + } + + private void assertSendKeyAll(IAerospikeClient client, boolean sendKey) { + assertEquals(client.getReadPolicyDefault().sendKey, sendKey); + assertEquals(client.getWritePolicyDefault().sendKey, sendKey); + assertEquals(client.getQueryPolicyDefault().sendKey, sendKey); + assertEquals(client.getScanPolicyDefault().sendKey, sendKey); + assertEquals(client.getBatchPolicyDefault().sendKey, sendKey); + } }