mirror of https://github.com/qortal/qortal
Qortal Core - Main Code Repository
Decentralized Data Network - Blockchain - TRUE Cross-Chain Trading - Application and Website Hosting - Much More - Qortal is the future internet infrastructure for the global digital world.
https://qortal.dev
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.0 KiB
90 lines
2.0 KiB
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; |
|
} |
|
|
|
}
|
|
|