Search in sources :

Example 1 with ConcurrentMutableMap

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);
}
Also used : RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) DataSourceWithStatistics(org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceWithStatistics) ConcurrentMutableMap(org.eclipse.collections.api.map.ConcurrentMutableMap) ConnectionKey(org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionKey) Identity(org.finos.legend.engine.shared.core.identity.Identity) Test(org.junit.Test)

Example 2 with ConcurrentMutableMap

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);
}
Also used : RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) DataSourceWithStatistics(org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceWithStatistics) ConcurrentMutableMap(org.eclipse.collections.api.map.ConcurrentMutableMap) ConnectionKey(org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionKey) Identity(org.finos.legend.engine.shared.core.identity.Identity) LocalH2DataSourceSpecification(org.finos.legend.engine.plan.execution.stores.relational.connection.ds.specifications.LocalH2DataSourceSpecification) DataSourceSpecification(org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceSpecification) StaticDataSourceSpecification(org.finos.legend.engine.plan.execution.stores.relational.connection.ds.specifications.StaticDataSourceSpecification) Test(org.junit.Test)

Example 3 with ConcurrentMutableMap

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);
}
Also used : RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) DataSourceWithStatistics(org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceWithStatistics) ConcurrentMutableMap(org.eclipse.collections.api.map.ConcurrentMutableMap) ConnectionKey(org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionKey) Identity(org.finos.legend.engine.shared.core.identity.Identity) Test(org.junit.Test)

Aggregations

ConcurrentMutableMap (org.eclipse.collections.api.map.ConcurrentMutableMap)3 ConnectionKey (org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionKey)3 DataSourceWithStatistics (org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceWithStatistics)3 RelationalDatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection)3 Identity (org.finos.legend.engine.shared.core.identity.Identity)3 Test (org.junit.Test)3 DataSourceSpecification (org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceSpecification)1 LocalH2DataSourceSpecification (org.finos.legend.engine.plan.execution.stores.relational.connection.ds.specifications.LocalH2DataSourceSpecification)1 StaticDataSourceSpecification (org.finos.legend.engine.plan.execution.stores.relational.connection.ds.specifications.StaticDataSourceSpecification)1