Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
Formatting, fixed a test failure occurring with a newly added test that
was merged in (logic error in my existing code)
  • Loading branch information
kevinrr888 committed Jun 3, 2024
1 parent 8d72860 commit 47d16b0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.io.UncheckedIOException;
import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -31,7 +32,6 @@

import org.apache.accumulo.core.fate.zookeeper.ZooUtil;
import org.apache.hadoop.io.DataInputBuffer;
import java.time.Duration;

/**
* Transaction Store: a place to save transactions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ protected void create(FateId fateId, FateKey key) {

@Override
public Optional<FateTxStore<T>> tryReserve(FateId fateId) {
// return an empty option if the FateId doesn't exist
if (_getStatus(fateId).equals(TStatus.UNKNOWN)) {
return Optional.empty();
}
// uniquely identify this attempt to reserve the fate operation data
FateReservation reservation = FateReservation.from(lockID, UUID.randomUUID());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -162,7 +163,7 @@ private void testReserveUnreserve(FateInstanceType storeType) throws Exception {
reservation.setStatus(ReadOnlyFateStore.TStatus.SUBMITTED);
assertEquals(ReadOnlyFateStore.TStatus.SUBMITTED, reservation.getStatus());
reservation.delete();
reservation.unreserve(0, TimeUnit.MILLISECONDS);
reservation.unreserve(Duration.ofMillis(0));
// Attempt to set a status on a tx that has been unreserved (should throw exception)
assertThrows(IllegalStateException.class,
() -> reservation.setStatus(ReadOnlyFateStore.TStatus.NEW));
Expand All @@ -179,8 +180,7 @@ public void testReserveNonExistentTxn() throws Exception {

private void testReserveNonExistentTxn(FateInstanceType storeType) throws Exception {
// Tests that reserve() doesn't hang indefinitely and instead throws an error
// on reserve() a non-existent transaction. Tests that tryReserve() will return
// an empty optional on non-existent transaction.
// on reserve() a non-existent transaction.
final FateStore<SleepingTestEnv> store;
final boolean isUserStore = storeType.equals(FateInstanceType.USER);
final String tableName = getUniqueNames(1)[0];
Expand All @@ -195,7 +195,6 @@ private void testReserveNonExistentTxn(FateInstanceType storeType) throws Except
}

assertThrows(IllegalStateException.class, () -> store.reserve(fakeFateId));
assertTrue(store.tryReserve(fakeFateId).isEmpty());
}

@Test
Expand Down Expand Up @@ -238,12 +237,11 @@ private void testReserveReservedAndUnreserveUnreserved(FateInstanceType storeTyp

// Unreserve all the FateIds
for (var reservation : reservations) {
reservation.unreserve(0, TimeUnit.MILLISECONDS);
reservation.unreserve(Duration.ofMillis(0));
}
// Try to unreserve again (should throw exception)
for (var reservation : reservations) {
assertThrows(IllegalStateException.class,
() -> reservation.unreserve(0, TimeUnit.MILLISECONDS));
assertThrows(IllegalStateException.class, () -> reservation.unreserve(Duration.ofMillis(0)));
}
}

Expand Down Expand Up @@ -282,7 +280,7 @@ private void testReserveAfterUnreserveAndReserveAfterDeleted(FateInstanceType st

// Unreserve all
for (var reservation : reservations) {
reservation.unreserve(0, TimeUnit.MILLISECONDS);
reservation.unreserve(Duration.ofMillis(0));
}

// Ensure they can be reserved again, and delete and unreserve this time
Expand All @@ -292,7 +290,7 @@ private void testReserveAfterUnreserveAndReserveAfterDeleted(FateInstanceType st
var reservation = store.tryReserve(fateId);
assertFalse(reservation.isEmpty());
reservation.orElseThrow().delete();
reservation.orElseThrow().unreserve(0, TimeUnit.MILLISECONDS);
reservation.orElseThrow().unreserve(Duration.ofMillis(0));
}

for (FateId fateId : allIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public void executeTest(FateTestExecutor<FilTestEnv> testMethod, int maxDeferred
String path = ZK_ROOT + Constants.ZFATE;
ZooReaderWriter zk = sctx.getZooReaderWriter();
zk.mkdirs(ZK_ROOT);
testMethod.execute(new MetaFateStore<>(path, zk), sctx);
testMethod.execute(
new MetaFateStore<>(path, zk, sctx.getZooCache(), AbstractFateStore.createDummyLockID()),
sctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void executeTest(FateTestExecutor<FilTestEnv> testMethod, int maxDeferred
try (ClientContext client =
(ClientContext) Accumulo.newClient().from(getClientProps()).build()) {
createFateTable(client, table);
testMethod.execute(new UserFateStore<>(client, table, maxDeferred, fateIdGenerator),
getCluster().getServerContext());
testMethod.execute(new UserFateStore<>(client, table, AbstractFateStore.createDummyLockID(),
maxDeferred, fateIdGenerator), getCluster().getServerContext());
client.tableOperations().delete(table);
}
}
Expand Down

0 comments on commit 47d16b0

Please sign in to comment.