forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-5861: change jdbc connector to use jndi binding (apache#2650)
The jdbc connector now uses the existing "jndi-binding" xml/gfsh instead of adding "jdbc-connection" xml/gfsh. All the old "jdbc-connection" commands have been removed. The create jndi-binding command has been changed in the following ways: * the driver-class-name gfsh parameter is now optional. * --url can be used as a replacement for --connnection-url * the --type now defaults to SIMPLE (it used to not have a default). * the --type=POOLED now defaults to creating a Hikari pool and an SPI exists to customize the class that implements the pool. New External APIS: DataSourceFactoryTest: this is the SPI users can implement for the POOLED type. Co-authored-by: @BenjaminPerryRoss
- Loading branch information
1 parent
1c55639
commit 404c64d
Showing
90 changed files
with
788 additions
and
4,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...cceptanceTest/java/org/apache/geode/connectors/jdbc/CreatePooledJndiBindingDUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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.geode.connectors.jdbc; | ||
|
||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.NodeList; | ||
|
||
import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService; | ||
import org.apache.geode.internal.jndi.JNDIInvoker; | ||
import org.apache.geode.management.internal.configuration.domain.Configuration; | ||
import org.apache.geode.management.internal.configuration.utils.XmlUtils; | ||
import org.apache.geode.test.dunit.rules.ClusterStartupRule; | ||
import org.apache.geode.test.dunit.rules.MemberVM; | ||
import org.apache.geode.test.junit.categories.JDBCConnectorTest; | ||
import org.apache.geode.test.junit.rules.GfshCommandRule; | ||
import org.apache.geode.test.junit.rules.VMProvider; | ||
|
||
@Category({JDBCConnectorTest.class}) | ||
public class CreatePooledJndiBindingDUnitTest { | ||
|
||
private MemberVM locator, server1, server2; | ||
|
||
@Rule | ||
public ClusterStartupRule cluster = new ClusterStartupRule(); | ||
|
||
@Rule | ||
public GfshCommandRule gfsh = new GfshCommandRule(); | ||
|
||
|
||
@Before | ||
public void before() throws Exception { | ||
locator = cluster.startLocatorVM(0); | ||
server1 = cluster.startServerVM(1, "group1", locator.getPort()); | ||
server2 = cluster.startServerVM(2, "group1", locator.getPort()); | ||
|
||
gfsh.connectAndVerify(locator); | ||
} | ||
|
||
@Test | ||
public void testCreateJndiBinding() throws Exception { | ||
// assert that is no datasource | ||
VMProvider.invokeInEveryMember( | ||
() -> assertThat(JNDIInvoker.getNoOfAvailableDataSources()).isEqualTo(0)); | ||
|
||
// create the binding | ||
gfsh.executeAndAssertThat( | ||
"create jndi-binding --name=jndi1 --username=myuser --password=mypass --type=POOLED --connection-url=\"jdbc:derby:newDB;create=true\" --conn-pooled-datasource-class=org.apache.geode.internal.jta.CacheJTAPooledDataSourceFactory") | ||
.statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1", "server-2"); | ||
|
||
// verify cluster config is updated | ||
locator.invoke(() -> { | ||
InternalConfigurationPersistenceService ccService = | ||
ClusterStartupRule.getLocator().getConfigurationPersistenceService(); | ||
Configuration configuration = ccService.getConfiguration("cluster"); | ||
String xmlContent = configuration.getCacheXmlContent(); | ||
|
||
Document document = XmlUtils.createDocumentFromXml(xmlContent); | ||
NodeList jndiBindings = document.getElementsByTagName("jndi-binding"); | ||
|
||
assertThat(jndiBindings.getLength()).isEqualTo(1); | ||
assertThat(xmlContent).contains("user-name=\"myuser\""); | ||
assertThat(xmlContent).contains("password=\"mypass\""); | ||
|
||
boolean found = false; | ||
for (int i = 0; i < jndiBindings.getLength(); i++) { | ||
Element eachBinding = (Element) jndiBindings.item(i); | ||
if (eachBinding.getAttribute("jndi-name").equals("jndi1")) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
assertThat(found).isTrue(); | ||
}); | ||
|
||
// verify datasource exists | ||
VMProvider.invokeInEveryMember( | ||
() -> assertThat(JNDIInvoker.getNoOfAvailableDataSources()).isEqualTo(1), server1, server2); | ||
|
||
// bounce server1 | ||
server1.stop(false); | ||
server1 = cluster.startServerVM(1, locator.getPort()); | ||
|
||
// verify it has recreated the datasource from cluster config | ||
server1.invoke(() -> { | ||
assertThat(JNDIInvoker.getNoOfAvailableDataSources()).isEqualTo(1); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ctors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/TestDataSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.geode.connectors.jdbc; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
|
||
import org.apache.geode.connectors.jdbc.internal.SqlHandler.DataSourceFactory; | ||
|
||
public class TestDataSourceFactory implements DataSourceFactory { | ||
private final String url; | ||
private HikariDataSource dataSource; | ||
|
||
public TestDataSourceFactory(String url) { | ||
this.url = url; | ||
} | ||
|
||
@Override | ||
public DataSource getDataSource(String dataSourceName) { | ||
if (dataSource == null) { | ||
dataSource = new HikariDataSource(); | ||
dataSource.setJdbcUrl(url); | ||
} | ||
return dataSource; | ||
} | ||
|
||
public void close() { | ||
if (dataSource != null) { | ||
dataSource.close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.