From 86978bd81e138b26f052706e3cfb3193e66d5295 Mon Sep 17 00:00:00 2001 From: Daniil Kirilyuk Date: Tue, 6 Feb 2024 12:40:34 +0100 Subject: [PATCH] QPID-8666: [Broker-J] Broker plugin jdbc-provider-bone replacement (#239) --- ...onfigurationStoreUpgraderAndRecoverer.java | 2 +- .../BrokerStoreUpgraderAndRecoverer.java | 17 ++-- .../qpid/server/store/UpgraderHelper.java | 43 ++++---- .../VirtualHostStoreUpgraderAndRecoverer.java | 9 +- .../BrokerStoreUpgraderAndRecovererTest.java | 97 +++++++++++++++---- ...tualHostStoreUpgraderAndRecovererTest.java | 41 ++++---- .../qpid/server/test/AttributesUtils.java | 34 +++++++ .../hikaricp/HikariCPConnectionProvider.java | 12 +-- .../HikariCPConnectionProviderFactory.java | 4 +- .../management/store/pool/hikaricp/add.js | 4 +- .../management/store/pool/hikaricp/show.js | 2 +- .../resources/store/pool/hikaricp/show.html | 4 +- ...HikariCPConnectionProviderFactoryTest.java | 8 +- .../HikariCPConnectionProviderTest.java | 8 +- 14 files changed, 195 insertions(+), 90 deletions(-) create mode 100644 broker-core/src/test/java/org/apache/qpid/server/test/AttributesUtils.java diff --git a/broker-core/src/main/java/org/apache/qpid/server/store/AbstractConfigurationStoreUpgraderAndRecoverer.java b/broker-core/src/main/java/org/apache/qpid/server/store/AbstractConfigurationStoreUpgraderAndRecoverer.java index 90349ee905..da1d5e52ca 100644 --- a/broker-core/src/main/java/org/apache/qpid/server/store/AbstractConfigurationStoreUpgraderAndRecoverer.java +++ b/broker-core/src/main/java/org/apache/qpid/server/store/AbstractConfigurationStoreUpgraderAndRecoverer.java @@ -32,7 +32,7 @@ abstract class AbstractConfigurationStoreUpgraderAndRecoverer { protected static final String VIRTUALHOST = "VirtualHost"; - protected static final String JDBC_VIRTUALHOST_TYPE = "JDBC"; + protected static final String JDBC = "JDBC"; protected static final String CONTEXT = "context"; private final Map _upgraders = new HashMap<>(); diff --git a/broker-core/src/main/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecoverer.java b/broker-core/src/main/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecoverer.java index c06aaf3269..13823ad9fc 100644 --- a/broker-core/src/main/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecoverer.java +++ b/broker-core/src/main/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecoverer.java @@ -772,11 +772,13 @@ public Upgrader_9_0_to_9_1() } @Override - public void configuredObject(final ConfiguredObjectRecord record) + public void configuredObject(ConfiguredObjectRecord record) { if (BROKER.equals(record.getType())) { - upgradeRootRecord(record); + record = upgradeRootRecord(UpgraderHelper.upgradeConnectionPool(record)); + getUpdateMap().put(record.getId(), record); + return; } final Map attributes = record.getAttributes(); @@ -786,16 +788,13 @@ public void configuredObject(final ConfiguredObjectRecord record) return; } - if (!(VIRTUALHOST.equals(record.getType()) && JDBC_VIRTUALHOST_TYPE.equals(attributes.get("type")))) + if (!JDBC.equals(attributes.get("type"))) { return; } - if (attributes.containsKey(CONTEXT)) - { - final ConfiguredObjectRecord updatedRecord = UpgraderHelper.upgradeConnectionPool(record); - getUpdateMap().put(updatedRecord.getId(), updatedRecord); - } + final ConfiguredObjectRecord updatedRecord = UpgraderHelper.upgradeConnectionPool(record); + getUpdateMap().put(updatedRecord.getId(), updatedRecord); } @Override @@ -829,7 +828,7 @@ private static class VirtualHostEntryUpgrader addAttributeTransformer("storeUnderfullSize", copyAttribute()). addAttributeTransformer("storeOverfullSize", copyAttribute()). addAttributeTransformer("bdbEnvironmentConfig", mutateAttributeName(CONTEXT)), - JDBC_VIRTUALHOST_TYPE, new AttributesTransformer(). + JDBC, new AttributesTransformer(). addAttributeTransformer("id", copyAttribute()). addAttributeTransformer("name", copyAttribute()). addAttributeTransformer("createdTime", copyAttribute()). diff --git a/broker-core/src/main/java/org/apache/qpid/server/store/UpgraderHelper.java b/broker-core/src/main/java/org/apache/qpid/server/store/UpgraderHelper.java index 3569138697..e43df21acd 100644 --- a/broker-core/src/main/java/org/apache/qpid/server/store/UpgraderHelper.java +++ b/broker-core/src/main/java/org/apache/qpid/server/store/UpgraderHelper.java @@ -62,7 +62,8 @@ public static Map renameContextVariables(final Map { if (newContext.containsKey(oldName)) { - final String value = newContext.remove(oldName); + final Object object = newContext.remove(oldName); + final String value = object == null ? null : String.valueOf(object); newContext.put(newName, value); } }); @@ -79,6 +80,12 @@ public static ConfiguredObjectRecord upgradeConnectionPool(final ConfiguredObjec { final Map attributes = record.getAttributes(); + final Map updatedAttributes = new HashMap<>(record.getAttributes()); + if (BONECP.equals(attributes.get(CP_TYPE))) + { + updatedAttributes.put(CP_TYPE, HIKARICP); + } + final Object contextObject = attributes.get(CONTEXT); if (contextObject instanceof Map) @@ -86,25 +93,27 @@ public static ConfiguredObjectRecord upgradeConnectionPool(final ConfiguredObjec final Map context = (Map) contextObject; final Map newContext = UpgraderHelper.renameContextVariables(context, RENAME_MAPPING); - if (BONECP.equals(attributes.get(CP_TYPE))) - { - final int partitionCount = newContext.get(PARTITION_COUNT_PARAM) != null - ? Integer.parseInt(newContext.remove(PARTITION_COUNT_PARAM)) : 0; - final int maximumPoolSize = newContext.get(MAX_POOL_SIZE_PARAM) != null && partitionCount != 0 - ? Integer.parseInt(newContext.get(MAX_POOL_SIZE_PARAM)) * partitionCount : 40; - final int minIdle = newContext.get(MIN_IDLE_PARAM) != null && partitionCount != 0 - ? Integer.parseInt(newContext.get(MIN_IDLE_PARAM)) * partitionCount : 20; - newContext.put(MAX_POOL_SIZE_PARAM, String.valueOf(maximumPoolSize)); - newContext.put(MIN_IDLE_PARAM, String.valueOf(minIdle)); - } - final Map updatedAttributes = new HashMap<>(record.getAttributes()); - if (BONECP.equals(attributes.get(CP_TYPE))) + final int partitionCount = newContext.get(PARTITION_COUNT_PARAM) != null + ? Integer.parseInt(String.valueOf(newContext.remove(PARTITION_COUNT_PARAM))) : 0; + final int maximumPoolSize = newContext.get(MAX_POOL_SIZE_PARAM) != null && partitionCount != 0 + ? Integer.parseInt(String.valueOf(newContext.get(MAX_POOL_SIZE_PARAM))) * partitionCount : 40; + final int minIdle = newContext.get(MIN_IDLE_PARAM) != null && partitionCount != 0 + ? Integer.parseInt(String.valueOf(newContext.get(MIN_IDLE_PARAM))) * partitionCount : 20; + + if (BONECP.equals(attributes.get(CP_TYPE)) || "Broker".equals(record.getType())) { - updatedAttributes.put(CP_TYPE, HIKARICP); + if (newContext.containsKey(MAX_POOL_SIZE_PARAM)) + { + newContext.put(MAX_POOL_SIZE_PARAM, String.valueOf(maximumPoolSize)); + } + if (newContext.containsKey(MIN_IDLE_PARAM)) + { + newContext.put(MIN_IDLE_PARAM, String.valueOf(minIdle)); + } } + updatedAttributes.put(CONTEXT, newContext); - return new ConfiguredObjectRecordImpl(record.getId(), record.getType(), updatedAttributes, record.getParents()); } - return record; + return new ConfiguredObjectRecordImpl(record.getId(), record.getType(), updatedAttributes, record.getParents()); } } diff --git a/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java b/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java index 8ac13de12b..b1e2950ca2 100644 --- a/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java +++ b/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java @@ -1127,16 +1127,13 @@ public void configuredObject(final ConfiguredObjectRecord record) return; } - if (!(VIRTUALHOST.equals(record.getType()) && JDBC_VIRTUALHOST_TYPE.equals(attributes.get("type")))) + if (!JDBC.equals(attributes.get("type"))) { return; } - if (attributes.containsKey(CONTEXT)) - { - final ConfiguredObjectRecord updatedRecord = UpgraderHelper.upgradeConnectionPool(record); - getUpdateMap().put(updatedRecord.getId(), updatedRecord); - } + final ConfiguredObjectRecord updatedRecord = UpgraderHelper.upgradeConnectionPool(record); + getUpdateMap().put(updatedRecord.getId(), updatedRecord); } @Override diff --git a/broker-core/src/test/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecovererTest.java b/broker-core/src/test/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecovererTest.java index b344e14c2a..6731ea13bb 100644 --- a/broker-core/src/test/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecovererTest.java +++ b/broker-core/src/test/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecovererTest.java @@ -20,6 +20,7 @@ */ package org.apache.qpid.server.store; +import static org.apache.qpid.server.test.AttributesUtils.createAttributesMap; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -124,10 +125,9 @@ public void testUpgradeVirtualHostWithJDBCStoreAndBoneCPPool() "qpid.jdbcstore.varBinaryType", "myvarbinary", "qpid.jdbcstore.blobType", "myblob", "qpid.jdbcstore.useBytesForBlob", true, - "qpid.jdbcstore.bonecp.maxConnectionsPerPartition", 7, - "qpid.jdbcstore.bonecp.minConnectionsPerPartition", 6, - "qpid.jdbcstore.bonecp.partitionCount", 2); - final Map expectedAttributes = Map.of("connectionPoolType", "BONECP", + "qpid.jdbcstore.hikaricp.maximumPoolSize", "14", + "qpid.jdbcstore.hikaricp.minimumIdle", "12"); + final Map expectedAttributes = Map.of("connectionPoolType", "HIKARICP", "connectionUrl", "jdbc:derby://localhost:1527/tmp/vh/test;create=true", "createdBy", VIRTUALHOST_CREATED_BY, "createdTime", VIRTUALHOST_CREATE_TIME, @@ -898,27 +898,87 @@ public void testContextVariableUpgradeFromBoneCPToHikariCPProvider(final String context.put("qpid.jdbcstore.bonecp.partitionCount", partitionCount); context.put("qpid.jdbcstore.bonecp.maxConnectionsPerPartition", maxConnectionsPerPartition); context.put("qpid.jdbcstore.bonecp.minConnectionsPerPartition", minConnectionsPerPartition); + context.put("qpid.jdbcstore.property1", "1"); + context.put("qpid.jdbcstore.property2", "two"); + context.put("qpid.jdbcstore.property3", "_3_"); + final Map attributes = Map.of("name", getTestName(), "type", "JDBC", - "connectionPoolType", "BONECP", - "context", context); - final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class);; + "connectionPoolType", "BONECP"); + + _brokerRecord.getAttributes().put("context", new HashMap<>(context)); + + final ConfiguredObjectRecord systemConfigRecord = mock(ConfiguredObjectRecord.class); + when(systemConfigRecord.getId()).thenReturn(randomUUID()); + when(systemConfigRecord.getType()).thenReturn("SystemConfig"); + when(systemConfigRecord.getAttributes()).thenReturn(createAttributesMap(attributes, context)); + + final ConfiguredObjectRecord virtualHostNodeRecord = mock(ConfiguredObjectRecord.class); + when(virtualHostNodeRecord.getId()).thenReturn(randomUUID()); + when(virtualHostNodeRecord.getType()).thenReturn("VirtualHostNode"); + when(virtualHostNodeRecord.getAttributes()).thenReturn(createAttributesMap(attributes, context)); + + final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class); when(virtualHostRecord.getId()).thenReturn(randomUUID()); when(virtualHostRecord.getType()).thenReturn("VirtualHost"); - when(virtualHostRecord.getAttributes()).thenReturn(attributes); + when(virtualHostRecord.getAttributes()).thenReturn(createAttributesMap(attributes, context)); - final DurableConfigurationStore dcs = new DurableConfigurationStoreStub(virtualHostRecord, _brokerRecord); + final ConfiguredObjectRecord jdbcBrokerLoggerRecord = mock(ConfiguredObjectRecord.class); + when(jdbcBrokerLoggerRecord.getId()).thenReturn(randomUUID()); + when(jdbcBrokerLoggerRecord.getType()).thenReturn("BrokerLogger"); + when(jdbcBrokerLoggerRecord.getAttributes()).thenReturn(createAttributesMap(attributes, context)); + + final ConfiguredObjectRecord jdbcVirtualHostLoggerRecord = mock(ConfiguredObjectRecord.class); + when(jdbcVirtualHostLoggerRecord.getId()).thenReturn(randomUUID()); + when(jdbcVirtualHostLoggerRecord.getType()).thenReturn("VirtualHostLogger"); + when(jdbcVirtualHostLoggerRecord.getAttributes()).thenReturn(createAttributesMap(attributes, context)); + + final DurableConfigurationStore dcs = + new DurableConfigurationStoreStub(jdbcVirtualHostLoggerRecord, jdbcBrokerLoggerRecord, virtualHostRecord, + virtualHostNodeRecord, systemConfigRecord, _brokerRecord); final BrokerStoreUpgraderAndRecoverer recoverer = new BrokerStoreUpgraderAndRecoverer(_systemConfig); final List records = upgrade(dcs, recoverer); - final Map contextMap = findCategoryRecordAndGetContext("VirtualHost", records); + records.forEach(record -> + { + final Map upgradedContext = + (Map) record.getAttributes().get("context"); + + assertNull(upgradedContext.get("qpid.jdbcstore.bonecp.partitionCount")); + assertEquals(maximumPoolSize, upgradedContext.get("qpid.jdbcstore.hikaricp.maximumPoolSize")); + assertEquals(minimumIdle, upgradedContext.get("qpid.jdbcstore.hikaricp.minimumIdle")); + assertEquals("1", upgradedContext.get("qpid.jdbcstore.property1")); + assertEquals("two", upgradedContext.get("qpid.jdbcstore.property2")); + assertEquals("_3_", upgradedContext.get("qpid.jdbcstore.property3")); + if (!"Broker".equals(record.getType())) + { + assertEquals("HIKARICP", record.getAttributes().get("connectionPoolType")); + } + }); + } + + @Test + public void testUpgradeFromBoneCPToHikariCPProviderWithEmptyContext() + { + _brokerRecord.getAttributes().put("modelVersion", "9.0"); + + final Map attributes = Map.of("name", getTestName(), + "type", "JDBC", + "connectionPoolType", "BONECP"); + final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class); + when(virtualHostRecord.getId()).thenReturn(randomUUID()); + when(virtualHostRecord.getType()).thenReturn("VirtualHost"); + when(virtualHostRecord.getAttributes()).thenReturn(createAttributesMap(attributes, new HashMap<>())); + + final DurableConfigurationStore dcs = new DurableConfigurationStoreStub(virtualHostRecord, _brokerRecord); + final BrokerStoreUpgraderAndRecoverer recoverer = new BrokerStoreUpgraderAndRecoverer(_systemConfig); + final List records = upgrade(dcs, recoverer); final ConfiguredObjectRecord upgradedVirtualHost = records.stream() - .filter(record -> record.getType().equals("VirtualHost")).findFirst() - .orElse(null); + .filter(record -> "VirtualHost".equals(record.getType())).findFirst().orElse(null); + final Map contextMap = findCategoryRecordAndGetContext("VirtualHost", records); - assertNotNull(upgradedVirtualHost); - assertEquals(maximumPoolSize, contextMap.get("qpid.jdbcstore.hikaricp.maximumPoolSize")); - assertEquals(minimumIdle, contextMap.get("qpid.jdbcstore.hikaricp.minimumIdle")); + assertNull(contextMap.get("qpid.jdbcstore.hikaricp.maximumPoolSize")); + assertNull(contextMap.get("qpid.jdbcstore.hikaricp.minimumIdle")); assertEquals("HIKARICP", upgradedVirtualHost.getAttributes().get("connectionPoolType")); } @@ -929,12 +989,11 @@ public void testContextVariableUpgradeFromDefaultCPToHikariCPProvider() final Map attributes = Map.of("name", getTestName(), "type", "JDBC", - "connectionPoolType", "NONE", - "context", new HashMap<>()); - final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class);; + "connectionPoolType", "NONE"); + final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class); when(virtualHostRecord.getId()).thenReturn(randomUUID()); when(virtualHostRecord.getType()).thenReturn("VirtualHost"); - when(virtualHostRecord.getAttributes()).thenReturn(attributes); + when(virtualHostRecord.getAttributes()).thenReturn(createAttributesMap(attributes, new HashMap<>())); final DurableConfigurationStore dcs = new DurableConfigurationStoreStub(virtualHostRecord, _brokerRecord); final BrokerStoreUpgraderAndRecoverer recoverer = new BrokerStoreUpgraderAndRecoverer(_systemConfig); diff --git a/broker-core/src/test/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecovererTest.java b/broker-core/src/test/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecovererTest.java index 39970112b1..da27f724d3 100644 --- a/broker-core/src/test/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecovererTest.java +++ b/broker-core/src/test/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecovererTest.java @@ -19,6 +19,7 @@ package org.apache.qpid.server.store; +import static org.apache.qpid.server.test.AttributesUtils.createAttributesMap; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -323,29 +324,35 @@ public void testContextVariableUpgradeFromBoneCPToHikariCPProvider(final String context.put("qpid.jdbcstore.bonecp.partitionCount", partitionCount); context.put("qpid.jdbcstore.bonecp.maxConnectionsPerPartition", maxConnectionsPerPartition); context.put("qpid.jdbcstore.bonecp.minConnectionsPerPartition", minConnectionsPerPartition); + final Map attributes = Map.of("name", getTestName(), "modelVersion", "9.0", "type", "JDBC", - "connectionPoolType", "BONECP", - "context", context); - final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class);; + "connectionPoolType", "BONECP"); + + final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class); when(virtualHostRecord.getId()).thenReturn(randomUUID()); when(virtualHostRecord.getType()).thenReturn("VirtualHost"); - when(virtualHostRecord.getAttributes()).thenReturn(attributes); + when(virtualHostRecord.getAttributes()).thenReturn(createAttributesMap(attributes, context)); - final List records = List.of(rootRecord, virtualHostRecord); + final ConfiguredObjectRecord virtualHostLoggerRecord = mock(ConfiguredObjectRecord.class); + when(virtualHostLoggerRecord.getId()).thenReturn(randomUUID()); + when(virtualHostLoggerRecord.getType()).thenReturn("VirtualHostLogger"); + when(virtualHostLoggerRecord.getAttributes()).thenReturn(createAttributesMap(attributes, context)); + + final List records = List.of(rootRecord, virtualHostRecord, virtualHostLoggerRecord); final List upgradedRecords = _upgraderAndRecoverer.upgrade(_store, records, "VirtualHost", "modelVersion"); - final ConfiguredObjectRecord upgradedVirtualHost = upgradedRecords.stream() - .filter(record -> record.getId().equals(virtualHostRecord.getId())).findFirst() - .orElse(null); - final Map contextMap = (Map) upgradedVirtualHost.getAttributes().get("context"); + upgradedRecords.stream().filter(record -> !"root".equals(record.getAttributes().get("name"))).forEach(record -> + { + final Map upgradedContext = + (Map) record.getAttributes().get("context"); - assertNotNull(upgradedVirtualHost); - assertEquals(maximumPoolSize, contextMap.get("qpid.jdbcstore.hikaricp.maximumPoolSize")); - assertEquals(minimumIdle, contextMap.get("qpid.jdbcstore.hikaricp.minimumIdle")); - assertEquals("HIKARICP", upgradedVirtualHost.getAttributes().get("connectionPoolType")); + assertEquals(maximumPoolSize, upgradedContext.get("qpid.jdbcstore.hikaricp.maximumPoolSize")); + assertEquals(minimumIdle, upgradedContext.get("qpid.jdbcstore.hikaricp.minimumIdle")); + assertEquals("HIKARICP", record.getAttributes().get("connectionPoolType")); + }); } @Test @@ -357,12 +364,11 @@ public void testContextVariableUpgradeFromDefaultCPToHikariCPProvider() final Map attributes = Map.of("name", getTestName(), "modelVersion", "9.0", "type", "JDBC", - "connectionPoolType", "NONE", - "context", new HashMap<>()); - final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class);; + "connectionPoolType", "NONE"); + final ConfiguredObjectRecord virtualHostRecord = mock(ConfiguredObjectRecord.class); when(virtualHostRecord.getId()).thenReturn(randomUUID()); when(virtualHostRecord.getType()).thenReturn("VirtualHost"); - when(virtualHostRecord.getAttributes()).thenReturn(attributes); + when(virtualHostRecord.getAttributes()).thenReturn(createAttributesMap(attributes, new HashMap<>())); final List records = List.of(rootRecord, virtualHostRecord); final List upgradedRecords = @@ -374,6 +380,7 @@ public void testContextVariableUpgradeFromDefaultCPToHikariCPProvider() final Map contextMap = (Map) upgradedVirtualHost.getAttributes().get("context"); assertNotNull(upgradedVirtualHost); + assertNull(contextMap.get("qpid.jdbcstore.bonecp.partitionCount")); assertNull(contextMap.get("qpid.jdbcstore.hikaricp.maximumPoolSize")); assertNull(contextMap.get("qpid.jdbcstore.hikaricp.minimumIdle")); assertEquals("NONE", virtualHostRecord.getAttributes().get("connectionPoolType")); diff --git a/broker-core/src/test/java/org/apache/qpid/server/test/AttributesUtils.java b/broker-core/src/test/java/org/apache/qpid/server/test/AttributesUtils.java new file mode 100644 index 0000000000..5f2ecf5be6 --- /dev/null +++ b/broker-core/src/test/java/org/apache/qpid/server/test/AttributesUtils.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.test; + +import java.util.HashMap; +import java.util.Map; + +public class AttributesUtils +{ + /** Creates new attributes map along with the new context map */ + public static Map createAttributesMap(final Map attributes, + final Map context) + { + final Map copied = new HashMap<>(attributes); + copied.put("context", new HashMap<>(context)); + return copied; + } +} diff --git a/broker-plugins/jdbc-provider-hikari/src/main/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProvider.java b/broker-plugins/jdbc-provider-hikari/src/main/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProvider.java index 1e046f6e2f..351f2d9814 100644 --- a/broker-plugins/jdbc-provider-hikari/src/main/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProvider.java +++ b/broker-plugins/jdbc-provider-hikari/src/main/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProvider.java @@ -21,8 +21,8 @@ package org.apache.qpid.server.store.jdbc.hikaricp; import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.JDBC_STORE_PREFIX; -import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.MAX_POOLSIZE; -import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.MIN_IDLE; +import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.MAXIMUM_POOLSIZE; +import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.MINIMUM_IDLE; import java.sql.Connection; import java.sql.SQLException; @@ -48,8 +48,8 @@ public class HikariCPConnectionProvider implements ConnectionProvider private static final Logger LOGGER = LoggerFactory.getLogger(HikariCPConnectionProvider.class); private static final String ADDING_DATASOURCE_PROPERTY = "Adding dataSource property '{}' with value '{}'"; - public static final int DEFAULT_MIN_IDLE = 20; - public static final int DEFAULT_MAX_POOLSIZE = 40; + public static final int DEFAULT_MINIMUM_IDLE = 20; + public static final int DEFAULT_MAXIMUM_POOLSIZE = 40; private final HikariDataSource _dataSource; @@ -81,8 +81,8 @@ static HikariConfig createHikariCPConfig(final String connectionUrl, final Map providerAttributes) { final Map attributes = new HashMap<>(providerAttributes); - attributes.putIfAbsent(MIN_IDLE, String.valueOf(DEFAULT_MIN_IDLE)); - attributes.putIfAbsent(MAX_POOLSIZE, String.valueOf(DEFAULT_MAX_POOLSIZE)); + attributes.putIfAbsent(MINIMUM_IDLE, String.valueOf(DEFAULT_MINIMUM_IDLE)); + attributes.putIfAbsent(MAXIMUM_POOLSIZE, String.valueOf(DEFAULT_MAXIMUM_POOLSIZE)); final int prefixLength = (JDBC_STORE_PREFIX + "hikaricp.").length(); final Map propertiesMap = attributes.entrySet() diff --git a/broker-plugins/jdbc-provider-hikari/src/main/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderFactory.java b/broker-plugins/jdbc-provider-hikari/src/main/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderFactory.java index c553b4cc38..3db23f5588 100644 --- a/broker-plugins/jdbc-provider-hikari/src/main/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderFactory.java +++ b/broker-plugins/jdbc-provider-hikari/src/main/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderFactory.java @@ -40,8 +40,8 @@ public class HikariCPConnectionProviderFactory implements JDBCConnectionProvider { static final String JDBC_STORE_PREFIX = "qpid.jdbcstore."; static final String HIKARICP_SETTING_PREFIX = JDBC_STORE_PREFIX + "hikaricp."; - static final String MAX_POOLSIZE = HIKARICP_SETTING_PREFIX + "maximumPoolSize"; - static final String MIN_IDLE = HIKARICP_SETTING_PREFIX + "minimumIdle"; + static final String MAXIMUM_POOLSIZE = HIKARICP_SETTING_PREFIX + "maximumPoolSize"; + static final String MINIMUM_IDLE = HIKARICP_SETTING_PREFIX + "minimumIdle"; private final Set _supportedAttributes; diff --git a/broker-plugins/jdbc-provider-hikari/src/main/java/resources/js/qpid/management/store/pool/hikaricp/add.js b/broker-plugins/jdbc-provider-hikari/src/main/java/resources/js/qpid/management/store/pool/hikaricp/add.js index 9e723e7490..4988d66af3 100644 --- a/broker-plugins/jdbc-provider-hikari/src/main/java/resources/js/qpid/management/store/pool/hikaricp/add.js +++ b/broker-plugins/jdbc-provider-hikari/src/main/java/resources/js/qpid/management/store/pool/hikaricp/add.js @@ -37,8 +37,8 @@ define(["dojo/_base/xhr", show: function (data) { data.context.addInheritedContext({ - "qpid.jdbcstore.hikaricp.minIdle": "5", - "qpid.jdbcstore.hikaricp.maxPoolsize": "10" + "qpid.jdbcstore.hikaricp.minimumIdle": "20", + "qpid.jdbcstore.hikaricp.maximumPoolSize": "40" }); } }; diff --git a/broker-plugins/jdbc-provider-hikari/src/main/java/resources/js/qpid/management/store/pool/hikaricp/show.js b/broker-plugins/jdbc-provider-hikari/src/main/java/resources/js/qpid/management/store/pool/hikaricp/show.js index 9ddd17ab6f..4d9c25e188 100644 --- a/broker-plugins/jdbc-provider-hikari/src/main/java/resources/js/qpid/management/store/pool/hikaricp/show.js +++ b/broker-plugins/jdbc-provider-hikari/src/main/java/resources/js/qpid/management/store/pool/hikaricp/show.js @@ -21,7 +21,7 @@ define(["dojo/_base/xhr", "dojo/parser", "dojox/html/entities", "dojo/query", "dojo/_base/lang", "dojo/domReady!"], function (xhr, parser, entities, query, lang) { - var fieldNames = ["maxPoolsize", "minIdle"]; + var fieldNames = ["maximumPoolSize", "minimumIdle"]; function HikariCP(data) { diff --git a/broker-plugins/jdbc-provider-hikari/src/main/java/resources/store/pool/hikaricp/show.html b/broker-plugins/jdbc-provider-hikari/src/main/java/resources/store/pool/hikaricp/show.html index a7f8f24d1d..221a4937e8 100644 --- a/broker-plugins/jdbc-provider-hikari/src/main/java/resources/store/pool/hikaricp/show.html +++ b/broker-plugins/jdbc-provider-hikari/src/main/java/resources/store/pool/hikaricp/show.html @@ -21,11 +21,11 @@
Minimum Idle Connections:
-
+
Maximum Pool Size:
-
+
diff --git a/broker-plugins/jdbc-provider-hikari/src/test/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderFactoryTest.java b/broker-plugins/jdbc-provider-hikari/src/test/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderFactoryTest.java index 2ffae7a95c..271daf6121 100644 --- a/broker-plugins/jdbc-provider-hikari/src/test/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderFactoryTest.java +++ b/broker-plugins/jdbc-provider-hikari/src/test/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderFactoryTest.java @@ -20,8 +20,8 @@ */ package org.apache.qpid.server.store.jdbc.hikaricp; -import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.MAX_POOLSIZE; -import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.MIN_IDLE; +import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.MAXIMUM_POOLSIZE; +import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProviderFactory.MINIMUM_IDLE; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -40,7 +40,7 @@ public void testGetProviderAttributeNames() Set supported = factory.getProviderAttributeNames(); assertFalse(supported.isEmpty(), "Supported settings cannot be empty"); - assertTrue(supported.contains(MAX_POOLSIZE), "maximumPoolSize is not found"); - assertTrue(supported.contains(MIN_IDLE), "minimumIdle is not found"); + assertTrue(supported.contains(MAXIMUM_POOLSIZE), "maximumPoolSize is not found"); + assertTrue(supported.contains(MINIMUM_IDLE), "minimumIdle is not found"); } } diff --git a/broker-plugins/jdbc-provider-hikari/src/test/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderTest.java b/broker-plugins/jdbc-provider-hikari/src/test/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderTest.java index 7b495c0601..4ea69afc22 100644 --- a/broker-plugins/jdbc-provider-hikari/src/test/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderTest.java +++ b/broker-plugins/jdbc-provider-hikari/src/test/java/org/apache/qpid/server/store/jdbc/hikaricp/HikariCPConnectionProviderTest.java @@ -20,8 +20,8 @@ */ package org.apache.qpid.server.store.jdbc.hikaricp; -import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProvider.DEFAULT_MAX_POOLSIZE; -import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProvider.DEFAULT_MIN_IDLE; +import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProvider.DEFAULT_MAXIMUM_POOLSIZE; +import static org.apache.qpid.server.store.jdbc.hikaricp.HikariCPConnectionProvider.DEFAULT_MINIMUM_IDLE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -73,7 +73,7 @@ public void testCreateHikariCPConfig() assertEquals("12345678", config.getDataSourceProperties().get("sslpassword"), "Unexpected sslpassword"); assertEquals("/etc/cert/trust.p12", config.getDataSourceProperties().get("sslcert"), "Unexpected sslcert"); assertEquals("12345678", config.getDataSourceProperties().get("certpassword"), "Unexpected certpassword"); - assertEquals(DEFAULT_MAX_POOLSIZE, config.getMaximumPoolSize(), "Unexpected maximumPoolSize"); - assertEquals(DEFAULT_MIN_IDLE, config.getMinimumIdle(), "Unexpected minimumIdle"); + assertEquals(DEFAULT_MAXIMUM_POOLSIZE, config.getMaximumPoolSize(), "Unexpected maximumPoolSize"); + assertEquals(DEFAULT_MINIMUM_IDLE, config.getMinimumIdle(), "Unexpected minimumIdle"); } }