use of org.eclipse.collections.api.map.ConcurrentMutableMap in project legend-engine by finos.
the class TestDatasourceCreation method userAcquiresConcurrentConnectionsToDifferentDbs.
@Test
public void userAcquiresConcurrentConnectionsToDifferentDbs() throws Exception {
ConcurrentMutableMap datasourceSpecifications = null;
Identity identity = IdentityFactoryProvider.getInstance().makeIdentityForTesting("testuser1");
// User gets connection to db1
RelationalDatabaseConnection database1 = buildStaticDatabaseSpec("127.0.0.1", server.getPort(), "db2");
ConnectionKey connectionKey = this.connectionManagerSelector.generateKeyFromDatabaseConnection(database1);
String pool1 = this.connectionStateManager.poolNameFor(identity, connectionKey);
this.connectionManagerSelector.getDatabaseConnection(identity, database1);
// We have a single data source
datasourceSpecifications = ConnectionPoolTestUtils.getDataSourceSpecifications();
assertEquals(1, datasourceSpecifications.size());
// We have a single data source for user1
DataSourceWithStatistics datasource1 = this.getDatasourceByPool(pool1);
// User gets another connection to db2
RelationalDatabaseConnection database2 = buildStaticDatabaseSpec("127.0.0.1", server.getPort(), "db3");
ConnectionKey key2 = this.connectionManagerSelector.generateKeyFromDatabaseConnection(database2);
String pool2 = this.connectionStateManager.poolNameFor(identity, key2);
this.connectionManagerSelector.getDatabaseConnection(identity, database2);
// We now have 2 data sources one per database
datasourceSpecifications = ConnectionPoolTestUtils.getDataSourceSpecifications();
assertEquals(2, datasourceSpecifications.size());
// We have a single data source for user2
DataSourceWithStatistics datasource2 = this.getDatasourceByPool(pool2);
assertNotSame("found same datasource when distinct datasources was expected", datasource1, datasource2);
}
use of org.eclipse.collections.api.map.ConcurrentMutableMap in project legend-engine by finos.
the class TestDatasourceCreation method multipleUsersAcquireConnectionsToDifferentDatabases.
@Test
public void multipleUsersAcquireConnectionsToDifferentDatabases() throws Exception {
ConcurrentMutableMap datasourceSpecifications = null;
Identity identity1 = IdentityFactoryProvider.getInstance().makeIdentityForTesting("testuser1");
// User gets connection to db1
RelationalDatabaseConnection database1 = buildStaticDatabaseSpec("127.0.0.1", server.getPort(), "db4");
ConnectionKey connectionKey = this.connectionManagerSelector.generateKeyFromDatabaseConnection(database1);
String key1 = this.connectionStateManager.poolNameFor(identity1, connectionKey);
this.connectionManagerSelector.getDatabaseConnection(identity1, database1);
DataSourceSpecification ds = builStaticDataSourceSpecification("127.0.0.1", server.getPort(), "db4");
assertEquals(ds.getConnectionKey(), connectionKey);
// We have a single data source
datasourceSpecifications = ConnectionPoolTestUtils.getDataSourceSpecifications();
assertEquals(1, datasourceSpecifications.size());
// We have a single data source for user1
DataSourceWithStatistics datasource1 = this.getDatasourceByPool(key1);
Identity identity2 = IdentityFactoryProvider.getInstance().makeIdentityForTesting("testuser2");
// User gets another connection to db2
RelationalDatabaseConnection database2 = buildStaticDatabaseSpec("127.0.0.1", server.getPort(), "db5");
ConnectionKey key2 = this.connectionManagerSelector.generateKeyFromDatabaseConnection(database2);
String pool2 = this.connectionStateManager.poolNameFor(identity2, key2);
this.connectionManagerSelector.getDatabaseConnection(identity2, database2);
// We now have 2 data sources one per database + user
datasourceSpecifications = ConnectionPoolTestUtils.getDataSourceSpecifications();
assertEquals(2, datasourceSpecifications.size());
// We have a single data source for user2
DataSourceWithStatistics datasource2 = this.getDatasourceByPool(pool2);
assertNotSame("found same datasource when distinct datasources was expected", datasource1, datasource2);
}
use of org.eclipse.collections.api.map.ConcurrentMutableMap in project legend-engine by finos.
the class TestDatasourceCreation method userAcquiresConcurrentConnectionsToSameDb.
@Test
public void userAcquiresConcurrentConnectionsToSameDb() throws Exception {
ConcurrentMutableMap datasourceSpecifications = null;
Identity identity = IdentityFactoryProvider.getInstance().makeIdentityForTesting("testuser1");
// User gets connection to db1
RelationalDatabaseConnection database1 = buildStaticDatabaseSpec("127.0.0.1", server.getPort(), "db1");
ConnectionKey connectionKey = this.connectionManagerSelector.generateKeyFromDatabaseConnection(database1);
String key = this.connectionStateManager.poolNameFor(identity, connectionKey);
this.connectionManagerSelector.getDatabaseConnection(identity, database1);
// We have a single data source
datasourceSpecifications = ConnectionPoolTestUtils.getDataSourceSpecifications();
assertEquals(1, datasourceSpecifications.size());
// We have a single data source for user1
DataSourceWithStatistics datasource1 = this.getDatasourceByPool(key);
// User gets another connection to db1
this.connectionManagerSelector.getDatabaseConnection(identity, database1);
// We still have a single data source for user1
datasourceSpecifications = ConnectionPoolTestUtils.getDataSourceSpecifications();
assertEquals(1, datasourceSpecifications.size());
DataSourceWithStatistics datasource2 = this.getDatasourceByPool(key);
assertSame("found distinct datasources when same datasource was expected", datasource1, datasource2);
}
Aggregations