qortal/tests/test/ExceptionTests.java
catbref eaad565765 Moved tests to outside of src/ path
This allows them to be excluded from final built package.

pom.xml and .classpath updated

Unable to test due to lack of JUnit 5 in Eclipse Neon
2018-11-02 15:52:09 +00:00

91 lines
2.0 KiB
Java

package test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import qora.block.Block;
public class ExceptionTests {
/**
* Proof of concept for block processing throwing transaction-related SQLException rather than savepoint-rollback-related SQLException.
* <p>
* See {@link Block#isValid(Connection)}.
*/
@Test
public void testBlockProcessingExceptions() {
try {
simulateThrow();
fail("Should not return result");
} catch (Exception e) {
assertEquals("Transaction issue", e.getMessage());
}
try {
boolean result = simulateFalse();
assertFalse(result);
} catch (Exception e) {
fail("Unexpected exception: " + e.getMessage());
}
try {
boolean result = simulateTrue();
assertTrue(result);
} catch (Exception e) {
fail("Unexpected exception: " + e.getMessage());
}
}
public boolean simulateThrow() throws Exception {
// simulate create savepoint (no-op)
try {
// simulate processing transactions but an exception is thrown
throw new Exception("Transaction issue");
} finally {
// attempt to rollback
try {
// simulate failing to rollback due to prior exception
throw new Exception("Rollback issue");
} catch (Exception e) {
// test discard of rollback exception, leaving prior exception
}
}
}
public boolean simulateFalse() throws Exception {
// simulate create savepoint (no-op)
try {
// simulate processing transactions but false returned
return false;
} finally {
// attempt to rollback
try {
// simulate successful rollback (no-op)
} catch (Exception e) {
// test discard of rollback exception, leaving prior exception
}
}
}
public boolean simulateTrue() throws Exception {
// simulate create savepoint (no-op)
try {
// simulate processing transactions successfully
} finally {
// attempt to rollback
try {
// simulate successful rollback (no-op)
} catch (Exception e) {
// test discard of rollback exception, leaving prior exception
}
}
return true;
}
}