From ddd36f403fae6c5c28e67296a042bb904b37fbf9 Mon Sep 17 00:00:00 2001 From: Milder Hernandez Cagua Date: Mon, 9 Oct 2023 11:30:58 -0700 Subject: [PATCH] Add test with existing database objects --- .../memory/jdbc/JDBCMemoryStoreTest.java | 18 ++++++++++----- .../memory/mysql/MySQLMemoryStoreTest.java | 22 +++++++++++++------ .../postgresql/PostgreSQLMemoryStoreTest.java | 18 ++++++++++----- .../memory/sqlite/SQLiteMemoryStoreTest.java | 13 ++++++++++- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/jdbc/JDBCMemoryStoreTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/jdbc/JDBCMemoryStoreTest.java index 499c35740654..9f6903e0aea7 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/jdbc/JDBCMemoryStoreTest.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/jdbc/JDBCMemoryStoreTest.java @@ -32,6 +32,7 @@ public class JDBCMemoryStoreTest { + private static JDBCMemoryStore.Builder builder; private static MemoryStore db; private static int collectionNum = 0; private static final String NULL_ADDITIONAL_METADATA = null; @@ -40,11 +41,9 @@ public class JDBCMemoryStoreTest { @BeforeAll static void setUp() throws SQLException { - db = - new JDBCMemoryStore.Builder() - .withConnection(DriverManager.getConnection("jdbc:sqlite::memory:")) - .buildAsync() - .block(); + builder = new JDBCMemoryStore.Builder() + .withConnection(DriverManager.getConnection("jdbc:sqlite::memory:")); + db = builder.buildAsync().block(); } private Collection createBatchRecords(int numRecords) { @@ -86,6 +85,15 @@ void initializeDbConnectionSucceeds() { assertNotNull(db); } + @Test + void itDoesNotFailWithExistingTables() { + // Act + db = builder.buildAsync().block(); + + // Assert + assertNotNull(db); + } + @Test void itCanCreateAndGetCollectionAsync() { // Arrange diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/mysql/MySQLMemoryStoreTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/mysql/MySQLMemoryStoreTest.java index 0da882497fe6..f021ba731a1e 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/mysql/MySQLMemoryStoreTest.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/mysql/MySQLMemoryStoreTest.java @@ -29,6 +29,7 @@ public class MySQLMemoryStoreTest { private static final String MYSQL_USER = "test"; private static final String MYSQL_PASSWORD = "test"; + private static MySQLMemoryStore.Builder builder; private static MemoryStore db; private static int collectionNum = 0; private static final String NULL_ADDITIONAL_METADATA = null; @@ -37,13 +38,11 @@ public class MySQLMemoryStoreTest { @BeforeAll static void setUp() throws SQLException { - db = - new MySQLMemoryStore.Builder() - .withConnection( - DriverManager.getConnection( - CONTAINER.getJdbcUrl(), MYSQL_USER, MYSQL_PASSWORD)) - .buildAsync() - .block(); + builder = new MySQLMemoryStore.Builder() + .withConnection( + DriverManager.getConnection( + CONTAINER.getJdbcUrl(), MYSQL_USER, MYSQL_PASSWORD)); + db = builder.buildAsync().block(); } private Collection createBatchRecords(int numRecords) { @@ -85,6 +84,15 @@ void initializeDbConnectionSucceeds() { assertNotNull(db); } + @Test + void itDoesNotFailWithExistingTables() { + // Act + db = builder.buildAsync().block(); + + // Assert + assertNotNull(db); + } + @Test void itCanCreateAndGetCollectionAsync() throws IOException { // Arrange diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/postgresql/PostgreSQLMemoryStoreTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/postgresql/PostgreSQLMemoryStoreTest.java index 409d51077e4c..cea1cd4ec6d1 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/postgresql/PostgreSQLMemoryStoreTest.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/connectors/memory/postgresql/PostgreSQLMemoryStoreTest.java @@ -29,6 +29,7 @@ public class PostgreSQLMemoryStoreTest { private static final String POSTGRES_USER = "test"; private static final String POSTGRES_PASSWORD = "test"; + private static PostgreSQLMemoryStore.Builder builder; private static MemoryStore db; private static int collectionNum = 0; private static final String NULL_ADDITIONAL_METADATA = null; @@ -37,13 +38,11 @@ public class PostgreSQLMemoryStoreTest { @BeforeAll static void setUp() throws SQLException { - db = - new PostgreSQLMemoryStore.Builder() + builder = new PostgreSQLMemoryStore.Builder() .withConnection( DriverManager.getConnection( - CONTAINER.getJdbcUrl(), POSTGRES_USER, POSTGRES_PASSWORD)) - .buildAsync() - .block(); + CONTAINER.getJdbcUrl(), POSTGRES_USER, POSTGRES_PASSWORD)); + db = builder.buildAsync().block(); } private Collection createBatchRecords(int numRecords) { @@ -85,6 +84,15 @@ void initializeDbConnectionSucceeds() { assertNotNull(db); } + @Test + void itDoesNotFailWithExistingTables() { + // Act + db = builder.buildAsync().block(); + + // Assert + assertNotNull(db); + } + @Test void itCanCreateAndGetCollectionAsync() throws IOException { // Arrange diff --git a/java/connectors/semantickernel-connectors-memory-sqlite/src/test/java/com/microsoft/semantickernel/connectors/memory/sqlite/SQLiteMemoryStoreTest.java b/java/connectors/semantickernel-connectors-memory-sqlite/src/test/java/com/microsoft/semantickernel/connectors/memory/sqlite/SQLiteMemoryStoreTest.java index 5ce844233a09..16071f99cf8e 100644 --- a/java/connectors/semantickernel-connectors-memory-sqlite/src/test/java/com/microsoft/semantickernel/connectors/memory/sqlite/SQLiteMemoryStoreTest.java +++ b/java/connectors/semantickernel-connectors-memory-sqlite/src/test/java/com/microsoft/semantickernel/connectors/memory/sqlite/SQLiteMemoryStoreTest.java @@ -30,6 +30,7 @@ public class SQLiteMemoryStoreTest { + private static SQLiteMemoryStore.Builder builder; private static MemoryStore db; private static int collectionNum = 0; private static final String NULL_ADDITIONAL_METADATA = null; @@ -38,7 +39,8 @@ public class SQLiteMemoryStoreTest { @BeforeAll static void setUp() throws SQLException { - db = new SQLiteMemoryStore.Builder().withFilename(":memory:").buildAsync().block(); + builder = new SQLiteMemoryStore.Builder().withFilename(":memory:"); + db = builder.buildAsync().block(); } private Collection createBatchRecords(int numRecords) { @@ -80,6 +82,15 @@ void initializeDbConnectionSucceeds() { assertNotNull(db); } + @Test + void itDoesNotFailWithExistingTables() { + // Act + db = builder.buildAsync().block(); + + // Assert + assertNotNull(db); + } + @Test void itCanCreateAndGetCollectionAsync() { // Arrange