You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by va...@apache.org on 2023/06/29 07:48:16 UTC
[qpid-broker-j] branch main updated: QPID-8649: [Broker-J] JUnit 5 tests refactoring for amqp-1-0-bdb-store and amqp-1-0-jdbc-store (#187)
This is an automated email from the ASF dual-hosted git repository.
vavrtom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git
The following commit(s) were added to refs/heads/main by this push:
new 15bcc24301 QPID-8649: [Broker-J] JUnit 5 tests refactoring for amqp-1-0-bdb-store and amqp-1-0-jdbc-store (#187)
15bcc24301 is described below
commit 15bcc24301fbcec2a7c8417b8a618a9f3e793040
Author: Daniil Kirilyuk <da...@gmail.com>
AuthorDate: Thu Jun 29 09:48:10 2023 +0200
QPID-8649: [Broker-J] JUnit 5 tests refactoring for amqp-1-0-bdb-store and amqp-1-0-jdbc-store (#187)
---
.../protocol/v1_0/store/bdb/BDBLinkStoreTest.java | 35 +++++++++-------------
.../v1_0/store/jdbc/JDBCLinkStoreTest.java | 31 +++++--------------
2 files changed, 21 insertions(+), 45 deletions(-)
diff --git a/broker-plugins/amqp-1-0-bdb-store/src/test/java/org/apache/qpid/server/protocol/v1_0/store/bdb/BDBLinkStoreTest.java b/broker-plugins/amqp-1-0-bdb-store/src/test/java/org/apache/qpid/server/protocol/v1_0/store/bdb/BDBLinkStoreTest.java
index 19089295a2..6011cf00e0 100644
--- a/broker-plugins/amqp-1-0-bdb-store/src/test/java/org/apache/qpid/server/protocol/v1_0/store/bdb/BDBLinkStoreTest.java
+++ b/broker-plugins/amqp-1-0-bdb-store/src/test/java/org/apache/qpid/server/protocol/v1_0/store/bdb/BDBLinkStoreTest.java
@@ -39,23 +39,23 @@ import java.util.Collections;
import java.util.Map;
import java.util.Objects;
-import com.google.common.io.Files;
-
import com.sleepycat.je.CacheMode;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.io.TempDir;
import org.apache.qpid.server.protocol.v1_0.store.LinkStore;
import org.apache.qpid.server.protocol.v1_0.store.LinkStoreTestCase;
import org.apache.qpid.server.store.berkeleydb.BDBEnvironmentContainer;
import org.apache.qpid.server.store.berkeleydb.StandardEnvironmentConfiguration;
import org.apache.qpid.server.store.berkeleydb.StandardEnvironmentFacade;
-import org.apache.qpid.server.util.FileUtils;
import org.apache.qpid.test.utils.VirtualHostNodeStoreType;
-public class BDBLinkStoreTest extends LinkStoreTestCase
+class BDBLinkStoreTest extends LinkStoreTestCase
{
private StandardEnvironmentFacade _facade;
+
+ @TempDir
private File _storeFolder;
@Override
@@ -70,28 +70,25 @@ public class BDBLinkStoreTest extends LinkStoreTestCase
@Override
protected LinkStore createLinkStore()
{
- _storeFolder = Files.createTempDir();
- StandardEnvironmentConfiguration configuration = mock(StandardEnvironmentConfiguration.class);
+ final StandardEnvironmentConfiguration configuration = mock(StandardEnvironmentConfiguration.class);
when(configuration.getName()).thenReturn("test");
when(configuration.getStorePath()).thenReturn(_storeFolder.getAbsolutePath());
when(configuration.getCacheMode()).thenReturn(CacheMode.DEFAULT);
when(configuration.getParameters()).thenReturn(Collections.emptyMap());
when(configuration.getFacadeParameter(eq(Integer.class),
- eq(LOG_HANDLER_CLEANER_PROTECTED_FILES_LIMIT_PROPERTY_NAME),
- anyInt())).thenReturn(0);
- when(configuration.getFacadeParameter(eq(Map.class),
- any(),
- eq(JUL_LOGGER_LEVEL_OVERRIDE),
- any())).thenReturn(Collections.emptyMap());
+ eq(LOG_HANDLER_CLEANER_PROTECTED_FILES_LIMIT_PROPERTY_NAME),
+ anyInt())).thenReturn(0);
+ when(configuration.getFacadeParameter(eq(Map.class), any(), eq(JUL_LOGGER_LEVEL_OVERRIDE), any()))
+ .thenReturn(Collections.emptyMap());
when(configuration.getFacadeParameter(eq(Integer.class),
- eq(QPID_BROKER_BDB_COMMITER_NOTIFY_THRESHOLD),
- anyInt())).thenReturn(DEFAULT_QPID_BROKER_BDB_COMMITER_NOTIFY_THRESHOLD);
+ eq(QPID_BROKER_BDB_COMMITER_NOTIFY_THRESHOLD),
+ anyInt())).thenReturn(DEFAULT_QPID_BROKER_BDB_COMMITER_NOTIFY_THRESHOLD);
when(configuration.getFacadeParameter(eq(Long.class),
- eq(QPID_BROKER_BDB_COMMITER_WAIT_TIMEOUT),
- anyLong())).thenReturn(DEFAULT_QPID_BROKER_BDB_COMMITER_WAIT_TIMEOUT);
+ eq(QPID_BROKER_BDB_COMMITER_WAIT_TIMEOUT),
+ anyLong())).thenReturn(DEFAULT_QPID_BROKER_BDB_COMMITER_WAIT_TIMEOUT);
_facade = new StandardEnvironmentFacade(configuration);
- BDBEnvironmentContainer<?> environmentContainer = mock(BDBEnvironmentContainer.class);
+ final BDBEnvironmentContainer<?> environmentContainer = mock(BDBEnvironmentContainer.class);
when(environmentContainer.getEnvironmentFacade()).thenReturn(_facade);
return new BDBLinkStore(environmentContainer);
}
@@ -103,9 +100,5 @@ public class BDBLinkStoreTest extends LinkStoreTestCase
{
_facade.close();
}
- if (_storeFolder != null)
- {
- FileUtils.delete(_storeFolder, true);
- }
}
}
diff --git a/broker-plugins/amqp-1-0-jdbc-store/src/test/java/org/apache/qpid/server/protocol/v1_0/store/jdbc/JDBCLinkStoreTest.java b/broker-plugins/amqp-1-0-jdbc-store/src/test/java/org/apache/qpid/server/protocol/v1_0/store/jdbc/JDBCLinkStoreTest.java
index 1ee6a6191c..58fc094595 100644
--- a/broker-plugins/amqp-1-0-jdbc-store/src/test/java/org/apache/qpid/server/protocol/v1_0/store/jdbc/JDBCLinkStoreTest.java
+++ b/broker-plugins/amqp-1-0-jdbc-store/src/test/java/org/apache/qpid/server/protocol/v1_0/store/jdbc/JDBCLinkStoreTest.java
@@ -32,7 +32,7 @@ import org.apache.qpid.server.protocol.v1_0.store.LinkStoreTestCase;
import org.apache.qpid.server.store.jdbc.JDBCContainer;
import org.apache.qpid.server.store.jdbc.JDBCDetails;
-public class JDBCLinkStoreTest extends LinkStoreTestCase
+class JDBCLinkStoreTest extends LinkStoreTestCase
{
@Override
protected LinkStore createLinkStore()
@@ -42,7 +42,7 @@ public class JDBCLinkStoreTest extends LinkStoreTestCase
when(details.getTimestampType()).thenReturn("timestamp");
when(details.isUseBytesMethodsForBlob()).thenReturn(false);
- JDBCContainer jdbcContainer = mock(JDBCContainer.class);
+ final JDBCContainer jdbcContainer = mock(JDBCContainer.class);
when(jdbcContainer.getJDBCDetails()).thenReturn(details);
when(jdbcContainer.getTableNamePrefix()).thenReturn("testTablePrefix");
when(jdbcContainer.getConnection()).thenAnswer(invocation -> DriverManager.getConnection(getUrl() + ";create=true"));
@@ -53,36 +53,19 @@ public class JDBCLinkStoreTest extends LinkStoreTestCase
@Override
protected void deleteLinkStore()
{
- Connection connection = null;
- try
+ try (final Connection connection = DriverManager.getConnection(getUrl()))
{
- connection = DriverManager.getConnection(getUrl());
+ // called to check connection status for SQLException to be thrown
+ connection.isClosed();
}
catch (SQLException e)
{
- if (e.getSQLState().equalsIgnoreCase("08006"))
- {
- //expected and represents a clean shutdown of this database only, do nothing.
- }
- else
+ // SQLState 08006 expected and represents a clean shutdown of this database only, do nothing
+ if (!"08006".equalsIgnoreCase(e.getSQLState()))
{
throw new RuntimeException(e);
}
}
- finally
- {
- if (connection != null)
- {
- try
- {
- connection.close();
- }
- catch (SQLException e)
- {
- throw new RuntimeException(e);
- }
- }
- }
}
private String getUrl()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org