Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Nov 15, 2023
1 parent 195a6c1 commit ae24f73
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public CredentialVault getCredentialVault()
return null;
}

public abstract Connection getConnection();
public abstract Connection getConnection(AuthenticationConfiguration authenticationConfiguration);

public abstract Identity getIdentity();

Expand All @@ -137,11 +137,11 @@ public CredentialVault getCredentialVault()
@Test
public void runTest() throws Exception
{
this.connectionProvider.injectConnection(this.getConnection());
Identity identity = this.getIdentity();
AuthenticationConfiguration authenticationConfiguration = this.getAuthenticationConfiguration();
this.connectionProvider.injectConnection(this.getConnection(authenticationConfiguration));

Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, TEST_CONNECTION_IDENTIFIER, authenticationConfiguration);
Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, TEST_CONNECTION_IDENTIFIER);
T connection = this.connectionFactory.getConnection(identity, authenticator);

this.runTestWithConnection(connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public void setup()
.databaseSupport(this.environment.getDatabaseSupport(RelationalDatabaseType.POSTGRES))
.identifier(TEST_CONNECTION_IDENTIFIER)
.connectionSpecification(connectionSpecification)
.authenticationConfiguration(new UserPasswordAuthenticationConfiguration(
postgresContainer.getUser(),
new PropertiesFileSecret("passwordRef")
))
.build();
}

Expand Down Expand Up @@ -132,11 +136,9 @@ public void testBasicConnectionPooling() throws Exception
.build()
);
ConnectionSpecification connectionSpecification = this.connection.getConnectionSpecification();
AuthenticationConfiguration authenticationConfiguration = new UserPasswordAuthenticationConfiguration(
postgresContainer.getUser(),
new PropertiesFileSecret("passwordRef")
);
Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, TEST_CONNECTION_IDENTIFIER, authenticationConfiguration);
AuthenticationConfiguration authenticationConfiguration = this.connection.getAuthenticationConfiguration();

Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, TEST_CONNECTION_IDENTIFIER);

JDBCConnectionManager connectionManager = JDBCConnectionManager.getInstance();
Assertions.assertEquals(0, connectionManager.getPoolSize());
Expand Down Expand Up @@ -205,16 +207,13 @@ public void testConnectionPoolingForDifferentIdentities() throws Exception
.build()
);
ConnectionSpecification connectionSpecification = this.connection.getConnectionSpecification();
AuthenticationConfiguration authenticationConfiguration = new UserPasswordAuthenticationConfiguration(
postgresContainer.getUser(),
new PropertiesFileSecret("passwordRef")
);
AuthenticationConfiguration authenticationConfiguration = this.connection.getAuthenticationConfiguration();

JDBCConnectionManager connectionManager = JDBCConnectionManager.getInstance();
Assertions.assertEquals(0, connectionManager.getPoolSize());

// 1. Get a new connection for identity1, which should initialize a pool
this.connectionFactory.getConnection(identity1, this.connectionFactory.getAuthenticator(identity1, TEST_CONNECTION_IDENTIFIER, authenticationConfiguration));
this.connectionFactory.getConnection(identity1, this.connectionFactory.getAuthenticator(identity1, TEST_CONNECTION_IDENTIFIER));

String poolName1 = JDBCConnectionManager.getPoolName(identity1, connectionSpecification, authenticationConfiguration);
JDBCConnectionManager.ConnectionPool connectionPool1 = connectionManager.getPool(poolName1);
Expand All @@ -225,7 +224,7 @@ public void testConnectionPoolingForDifferentIdentities() throws Exception
Assertions.assertEquals(0, connectionPool1.getIdleConnections());

// 2. Get a new connection for identity2, which should initialize another pool
this.connectionFactory.getConnection(identity2, this.connectionFactory.getAuthenticator(identity2, TEST_CONNECTION_IDENTIFIER, authenticationConfiguration));
this.connectionFactory.getConnection(identity2, this.connectionFactory.getAuthenticator(identity2, TEST_CONNECTION_IDENTIFIER));

String poolName2 = JDBCConnectionManager.getPoolName(identity2, connectionSpecification, authenticationConfiguration);
JDBCConnectionManager.ConnectionPool connectionPool2 = connectionManager.getPool(poolName2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public CredentialVault getCredentialVault()
}

@Override
public Connection getConnection()
public Connection getConnection(AuthenticationConfiguration authenticationConfiguration)
{
ConnectionSpecification connectionSpecification = new StaticJDBCConnectionSpecification(
this.postgresContainer.getHost(),
Expand All @@ -86,6 +86,7 @@ public Connection getConnection()
.type(CoreAuthenticationMechanismType.USER_PASSWORD).build()
)
.connectionSpecification(connectionSpecification)
.authenticationConfiguration(authenticationConfiguration)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public CredentialVault getCredentialVault()
}

@Override
public Connection getConnection()
public Connection getConnection(AuthenticationConfiguration authenticationConfiguration)
{
SnowflakeConnectionSpecification connectionSpecification = new SnowflakeConnectionSpecification();
connectionSpecification.databaseName = "SUMMIT_DEV";
Expand All @@ -89,6 +89,7 @@ public Connection getConnection()
.build()
)
.connectionSpecification(connectionSpecification)
.authenticationConfiguration(authenticationConfiguration)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Iterable<? extends Processor<?>> getExtraProcessors()
Connection.class,
(element, context) ->
{
Root_meta_pure_metamodel_connection_Connection metamodel = new Root_meta_pure_metamodel_connection_Connection_Impl(element.name, null, context.pureModel.getClass("meta::pure::metamodel::connection::ConnectionDemo"))._name(element.name);
Root_meta_pure_metamodel_connection_Connection metamodel = new Root_meta_pure_metamodel_connection_Connection_Impl(element.name, null, context.pureModel.getClass("meta::pure::metamodel::connection::Connection"))._name(element.name);
connectionsIndex.put(context.pureModel.buildPackageString(element._package, element.name), metamodel);
metamodel._rawValue(element);
return metamodel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ private Connection visitElement(ConnectionParserGrammar.DatabaseConnectionElemen
Connection connection;
try
{
StringBuilder connectionDemoText = new StringBuilder();
StringBuilder text = new StringBuilder();
for (ConnectionParserGrammar.RawValueContentContext fragment : rawValueContext.rawValueContent())
{
connectionDemoText.append(fragment.getText());
text.append(fragment.getText());
}
String rawValueText = connectionDemoText.length() > 0 ? connectionDemoText.substring(0, connectionDemoText.length() - 2) : connectionDemoText.toString();
String rawValueText = text.length() > 0 ? text.substring(0, text.length() - 2) : text.toString();
// prepare island grammar walker source information
connection = PureProtocolObjectMapperFactory.getNewObjectMapper().readValue(rawValueText, Connection.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

public class ConnectionProtocolExtension implements PureProtocolExtension
{
public static final String CONNECTION_CLASSIFIER_PATH = "meta::pure::metamodel::connection::ConnectionDemo";
public static final String CONNECTION_CLASSIFIER_PATH = "meta::pure::metamodel::connection::Connection";

@Override
public List<Function0<List<ProtocolSubTypeInfo<?>>>> getExtraProtocolSubTypeInfoCollectors()
Expand Down

0 comments on commit ae24f73

Please sign in to comment.