TestTransaction should implement Transaction instead of TransactionBase
- Dominant language
- Java
- Stars
- 200
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
Currently, `TestTransaction` implements TransactionBase, but still has a `commit()` and `close()` method with the same signature as the `Transaction` interface, which itself extends `AutoCloseable`. It should implement `Transaction` instead.
`TestTransaction` also has a `done()` method that does:
```java
try {
commit();
} finally {
close();
}
```
Once `TestTransaction` is `AutoCloseable`, inheriting that from `Transaction`, the calls to `done()` can, and should, be converted to calls to `commit()` at the end of a try-with-resources block, and the `done()` method should be removed. This will make the lifecycle management of test transactions in the test code more clear, rather than relying on the implied `close()` method inside the `done()`. It will also make the order of `commit()` calls more clear when writing/maintaining test code. With `commit()` hidden inside the `done()` method, it's not immediately obvious when they are called.
This proposal would cause code written like:
```java
TestTransaction tx = new TextTransaction();
// ... stuff here
tx.done(); // implied commit() and close()
```
to be written more explicitly as:
```java
try (TestTransaction tx = new TextTransaction()) {
// ... stuff here
tx.commit(); // explicit commit()
} // auto closed
```
This example doesn't look that much better, but it's a big improvement when there are multiple transactions being created, committed, and closed in a test.
Contributor guide
Research direction
Start by locating the Java TestTransaction class and all callers of its done() method. Review how those callers create and finish transactions, then convert them to try-with-resources with explicit commit() calls and verify that done() is no longer needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100