qortal/tests/test/RepositoryTests.java

58 lines
1.3 KiB
Java
Raw Normal View History

package test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import repository.DataException;
import repository.Repository;
import repository.RepositoryManager;
public class RepositoryTests extends Common {
private static final Logger LOGGER = LogManager.getLogger(RepositoryTests.class);
@Test
public void testGetRepository() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
assertNotNull(repository);
}
}
@Test
public void testMultipleInstances() throws DataException {
int n_instances = 5;
Repository[] repositories = new Repository[n_instances];
for (int i = 0; i < n_instances; ++i) {
repositories[i] = RepositoryManager.getRepository();
assertNotNull(repositories[i]);
}
for (int i = 0; i < n_instances; ++i) {
repositories[i].close();
repositories[i] = null;
}
}
@Test
public void testAccessAfterClose() throws DataException {
HSQLDB issue, resource leak prevention, v1 differences HSQLDB v2.4.0 had some issue with non-padded, case-insensitive string comparisons. This is fixed in svn r5836-ish of HSQLDB but yet to be pushed out to new HSQLDB release. So this commit includes hsqldb-r5836.jar and modified pom.xml/.classpath for now. No need for duplicate, hidden creatorPublicKey in CancelOrderTransactionData, CreateOrderTransactionData and CreatePollTransactionData. Various changes to use more try-with-resources, especially with JDBC objects like Connection, Statement, PreparedStatement, ResultSet. Added loads of missing @Override annotations. Fixed bug in Asset exchange order matching where the matching logic loop would incorrectly adjust temporary amount fulfilled by the "want" asset amount (in matchedAmount) instead of the "have" asset amount (in tradePrice). Disabled check for duplicate asset name in IssueAssetTransactions for old v1 transactions. In HSQLDB repository we now use ResultSet.getTimestamp(index, UTC-calendar) to make sure we only store/fetch UTC timestamps. The UTC-calendar is made using static final TimeZone called HSQLDBRepository.UTC. To keep asset IDs in line with v1, Assets.asset_id values are generated on-the-fly in HSQLDB using a "before insert" trigger on Assets table. Corresponding code calling HSQLDBRepository.callIdentity() replaced with SELECT statement instead. Moved most of the HSQLDB connection properties from the connection URL to explicit code in HSQLDBRepositoryFactory. Fixed incorrect 'amount' lengths in PaymentTransformer, as used by MultiPayment and Arbitrary transaction types. Added support for mangled arbitrary transaction bytes when generating/verifying a v1 transaction signature. In v1 Arbitrary transactions, bytes-for-signing are lost prior to final payment (but only if there are any payments). Added corresponding code for multi-payment transactions in the same vein.
2018-08-07 15:44:41 +01:00
try (Repository repository = RepositoryManager.getRepository()) {
assertNotNull(repository);
HSQLDB issue, resource leak prevention, v1 differences HSQLDB v2.4.0 had some issue with non-padded, case-insensitive string comparisons. This is fixed in svn r5836-ish of HSQLDB but yet to be pushed out to new HSQLDB release. So this commit includes hsqldb-r5836.jar and modified pom.xml/.classpath for now. No need for duplicate, hidden creatorPublicKey in CancelOrderTransactionData, CreateOrderTransactionData and CreatePollTransactionData. Various changes to use more try-with-resources, especially with JDBC objects like Connection, Statement, PreparedStatement, ResultSet. Added loads of missing @Override annotations. Fixed bug in Asset exchange order matching where the matching logic loop would incorrectly adjust temporary amount fulfilled by the "want" asset amount (in matchedAmount) instead of the "have" asset amount (in tradePrice). Disabled check for duplicate asset name in IssueAssetTransactions for old v1 transactions. In HSQLDB repository we now use ResultSet.getTimestamp(index, UTC-calendar) to make sure we only store/fetch UTC timestamps. The UTC-calendar is made using static final TimeZone called HSQLDBRepository.UTC. To keep asset IDs in line with v1, Assets.asset_id values are generated on-the-fly in HSQLDB using a "before insert" trigger on Assets table. Corresponding code calling HSQLDBRepository.callIdentity() replaced with SELECT statement instead. Moved most of the HSQLDB connection properties from the connection URL to explicit code in HSQLDBRepositoryFactory. Fixed incorrect 'amount' lengths in PaymentTransformer, as used by MultiPayment and Arbitrary transaction types. Added support for mangled arbitrary transaction bytes when generating/verifying a v1 transaction signature. In v1 Arbitrary transactions, bytes-for-signing are lost prior to final payment (but only if there are any payments). Added corresponding code for multi-payment transactions in the same vein.
2018-08-07 15:44:41 +01:00
repository.close();
HSQLDB issue, resource leak prevention, v1 differences HSQLDB v2.4.0 had some issue with non-padded, case-insensitive string comparisons. This is fixed in svn r5836-ish of HSQLDB but yet to be pushed out to new HSQLDB release. So this commit includes hsqldb-r5836.jar and modified pom.xml/.classpath for now. No need for duplicate, hidden creatorPublicKey in CancelOrderTransactionData, CreateOrderTransactionData and CreatePollTransactionData. Various changes to use more try-with-resources, especially with JDBC objects like Connection, Statement, PreparedStatement, ResultSet. Added loads of missing @Override annotations. Fixed bug in Asset exchange order matching where the matching logic loop would incorrectly adjust temporary amount fulfilled by the "want" asset amount (in matchedAmount) instead of the "have" asset amount (in tradePrice). Disabled check for duplicate asset name in IssueAssetTransactions for old v1 transactions. In HSQLDB repository we now use ResultSet.getTimestamp(index, UTC-calendar) to make sure we only store/fetch UTC timestamps. The UTC-calendar is made using static final TimeZone called HSQLDBRepository.UTC. To keep asset IDs in line with v1, Assets.asset_id values are generated on-the-fly in HSQLDB using a "before insert" trigger on Assets table. Corresponding code calling HSQLDBRepository.callIdentity() replaced with SELECT statement instead. Moved most of the HSQLDB connection properties from the connection URL to explicit code in HSQLDBRepositoryFactory. Fixed incorrect 'amount' lengths in PaymentTransformer, as used by MultiPayment and Arbitrary transaction types. Added support for mangled arbitrary transaction bytes when generating/verifying a v1 transaction signature. In v1 Arbitrary transactions, bytes-for-signing are lost prior to final payment (but only if there are any payments). Added corresponding code for multi-payment transactions in the same vein.
2018-08-07 15:44:41 +01:00
try {
repository.discardChanges();
fail();
} catch (NullPointerException | DataException e) {
}
LOGGER.warn("Expect \"repository already closed\" complaint below");
}
}
}