Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify boolean assertions #23595

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private static void assertStatementWarnings(Statement statement, Future<?> futur
private static SQLWarning fromTrinoWarnings(List<TrinoWarning> warnings)
{
requireNonNull(warnings, "warnings is null");
assertThat(warnings.isEmpty()).isFalse();
assertThat(warnings).isNotEmpty();
Iterator<TrinoWarning> iterator = warnings.iterator();
TrinoSqlWarning first = toTrinoSqlWarning(iterator.next());
SQLWarning current = first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testPositionsSizeInBytes()
Block valueBlock = createSingleValueBlock(createExpectedValue(10));
Block rleBlock = RunLengthEncodedBlock.create(valueBlock, 10);
// Size in bytes is not fixed per position
assertThat(rleBlock.fixedSizeInBytesPerPosition().isEmpty()).isTrue();
assertThat(rleBlock.fixedSizeInBytesPerPosition()).isEmpty();
// Accepts specific position selection
boolean[] positions = new boolean[rleBlock.getPositionCount()];
positions[0] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void testSubmittedForDispatchedQuery()
});
localDispatchQuery.startWaitingForResources();
countDownLatch.await();
assertThat(localDispatchQuery.getDispatchInfo().getCoordinatorLocation().isPresent()).isTrue();
assertThat(localDispatchQuery.getDispatchInfo().getCoordinatorLocation()).isPresent();
}

private static class NoConnectorServicesProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public void testCommit()
.setTransactionId(transactionManager.beginTransaction(false))
.build();
QueryStateMachine stateMachine = createQueryStateMachine("COMMIT", session, transactionManager);
assertThat(stateMachine.getSession().getTransactionId().isPresent()).isTrue();
assertThat(stateMachine.getSession().getTransactionId()).isPresent();
assertThat(transactionManager.getAllTransactionInfos().size()).isEqualTo(1);

getFutureValue(new CommitTask(transactionManager).execute(new Commit(new NodeLocation(1, 1)), stateMachine, emptyList(), WarningCollector.NOOP));
assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isTrue();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();
}

@Test
Expand All @@ -104,9 +104,9 @@ public void testNoTransactionCommit()
.hasErrorCode(NOT_IN_TRANSACTION);

assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();
}

@Test
Expand All @@ -124,9 +124,9 @@ public void testUnknownTransactionCommit()
.hasErrorCode(UNKNOWN_TRANSACTION);

assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isTrue(); // Still issue clear signal
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();
}

private QueryStateMachine createQueryStateMachine(String query, Session session, TransactionManager transactionManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,13 @@ private static void assertState(QueryStateMachine stateMachine, QueryState expec
QueryInfo queryInfo = stateMachine.getQueryInfo(Optional.empty());
assertThat(queryInfo.getQueryId()).isEqualTo(TEST_SESSION.getQueryId());
assertThat(queryInfo.getSelf()).isEqualTo(LOCATION);
assertThat(queryInfo.getOutputStage().isPresent()).isFalse();
assertThat(queryInfo.getOutputStage()).isEmpty();
assertThat(queryInfo.getQuery()).isEqualTo(QUERY);
assertThat(queryInfo.getInputs()).containsExactlyElementsOf(INPUTS);
assertThat(queryInfo.getOutput()).isEqualTo(OUTPUT);
assertThat(queryInfo.getFieldNames()).containsExactlyElementsOf(OUTPUT_FIELD_NAMES);
assertThat(queryInfo.getUpdateType()).isEqualTo(UPDATE_TYPE);
assertThat(queryInfo.getQueryType().isPresent()).isTrue();
assertThat(queryInfo.getQueryType()).isPresent();
assertThat(queryInfo.getQueryType().get()).isEqualTo(QUERY_TYPE.get());

QueryStats queryStats = queryInfo.getQueryStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public void testRollback()
.setTransactionId(transactionManager.beginTransaction(false))
.build();
QueryStateMachine stateMachine = createQueryStateMachine("ROLLBACK", session, transactionManager);
assertThat(stateMachine.getSession().getTransactionId().isPresent()).isTrue();
assertThat(stateMachine.getSession().getTransactionId()).isPresent();
assertThat(transactionManager.getAllTransactionInfos().size()).isEqualTo(1);

getFutureValue(new RollbackTask(transactionManager).execute(new Rollback(new NodeLocation(1, 1)), stateMachine, emptyList(), WarningCollector.NOOP));
assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isTrue();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();
}

@Test
Expand All @@ -97,9 +97,9 @@ public void testNoTransactionRollback()
.hasErrorCode(NOT_IN_TRANSACTION);

assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();
}

@Test
Expand All @@ -114,9 +114,9 @@ public void testUnknownTransactionRollback()

getFutureValue(new RollbackTask(transactionManager).execute(new Rollback(new NodeLocation(1, 1)), stateMachine, emptyList(), WarningCollector.NOOP));
assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isTrue(); // Still issue clear signal
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();
}

private QueryStateMachine createQueryStateMachine(String query, Session session, TransactionManager transactionManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void testFinalStageInfoInternal()

// once the final stage info is available, verify that it is complete
stageInfo = finalStageInfo.get(1, MINUTES);
assertThat(stageInfo.getTasks().isEmpty()).isFalse();
assertThat(stageInfo.getTasks()).isNotEmpty();
assertThat(stageInfo.isFinalStageInfo()).isTrue();
assertThat(stage.getStageInfo()).isSameAs(stageInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ public void testNonTransactionalClient()
Session session = sessionBuilder().build();
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
assertThat(stateMachine.getSession().getTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getSession().getTransactionId()).isEmpty();

assertTrinoExceptionThrownBy(
() -> getFutureValue(new StartTransactionTask(transactionManager)
.execute(new StartTransaction(new NodeLocation(1, 1), ImmutableList.of()), stateMachine, emptyList(), WarningCollector.NOOP)))
.hasErrorCode(INCOMPATIBLE_CLIENT);

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();

assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();
}

@Test
Expand All @@ -118,10 +118,10 @@ public void testNestedTransaction()
.execute(new StartTransaction(new NodeLocation(1, 1), ImmutableList.of()), stateMachine, emptyList(), WarningCollector.NOOP)))
.hasErrorCode(NOT_SUPPORTED);

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();

assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();
}

@Test
Expand All @@ -132,11 +132,11 @@ public void testStartTransaction()
.build();
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
assertThat(stateMachine.getSession().getTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getSession().getTransactionId()).isEmpty();

getFutureValue(new StartTransactionTask(transactionManager).execute(new StartTransaction(new NodeLocation(1, 1), ImmutableList.of()), stateMachine, emptyList(), WarningCollector.NOOP));
assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isTrue();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isPresent();
assertThat(transactionManager.getAllTransactionInfos().size()).isEqualTo(1);

TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
Expand All @@ -151,15 +151,15 @@ public void testStartTransactionExplicitModes()
.build();
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
assertThat(stateMachine.getSession().getTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getSession().getTransactionId()).isEmpty();

getFutureValue(new StartTransactionTask(transactionManager).execute(
new StartTransaction(new NodeLocation(1, 1), ImmutableList.of(new Isolation(new NodeLocation(1, 1), Isolation.Level.SERIALIZABLE), new TransactionAccessMode(new NodeLocation(1, 1), true))),
stateMachine,
emptyList(),
WarningCollector.NOOP));
assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isTrue();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isPresent();
assertThat(transactionManager.getAllTransactionInfos().size()).isEqualTo(1);

TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
Expand All @@ -176,7 +176,7 @@ public void testStartTransactionTooManyIsolationLevels()
.build();
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
assertThat(stateMachine.getSession().getTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getSession().getTransactionId()).isEmpty();

assertTrinoExceptionThrownBy(() ->
getFutureValue(new StartTransactionTask(transactionManager).execute(
Expand All @@ -186,10 +186,10 @@ public void testStartTransactionTooManyIsolationLevels()
WarningCollector.NOOP)))
.hasErrorCode(SYNTAX_ERROR);

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();

assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();
}

@Test
Expand All @@ -200,7 +200,7 @@ public void testStartTransactionTooManyAccessModes()
.build();
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
assertThat(stateMachine.getSession().getTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getSession().getTransactionId()).isEmpty();

assertTrinoExceptionThrownBy(() ->
getFutureValue(new StartTransactionTask(transactionManager).execute(
Expand All @@ -210,10 +210,10 @@ public void testStartTransactionTooManyAccessModes()
WarningCollector.NOOP)))
.hasErrorCode(SYNTAX_ERROR);

assertThat(transactionManager.getAllTransactionInfos().isEmpty()).isTrue();
assertThat(transactionManager.getAllTransactionInfos()).isEmpty();

assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isEmpty();
}

@Test
Expand All @@ -231,15 +231,15 @@ public void testStartTransactionIdleExpiration()
NO_CATALOGS,
executor);
QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
assertThat(stateMachine.getSession().getTransactionId().isPresent()).isFalse();
assertThat(stateMachine.getSession().getTransactionId()).isEmpty();

getFutureValue(new StartTransactionTask(transactionManager).execute(
new StartTransaction(new NodeLocation(1, 1), ImmutableList.of()),
stateMachine,
emptyList(),
WarningCollector.NOOP));
assertThat(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId()).isFalse();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent()).isTrue();
assertThat(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId()).isPresent();

long start = System.nanoTime();
while (!transactionManager.getAllTransactionInfos().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testTasksComplete()
assertThat(driver1.getCompletedPhases()).isEqualTo(0);
assertThat(driver2.getCompletedPhases()).isEqualTo(0);
ticker.increment(60, SECONDS);
assertThat(taskExecutor.getStuckSplitTaskIds(splitProcessingDurationThreshold, runningSplitInfo -> true).isEmpty()).isTrue();
assertThat(taskExecutor.getStuckSplitTaskIds(splitProcessingDurationThreshold, runningSplitInfo -> true)).isEmpty();
assertThat(taskExecutor.getRunAwaySplitCount()).isEqualTo(0);
ticker.increment(600, SECONDS);
assertThat(taskExecutor.getRunAwaySplitCount()).isEqualTo(2);
Expand Down Expand Up @@ -146,7 +146,7 @@ public void testTasksComplete()

// no splits remaining
ticker.increment(610, SECONDS);
assertThat(taskExecutor.getStuckSplitTaskIds(splitProcessingDurationThreshold, runningSplitInfo -> true).isEmpty()).isTrue();
assertThat(taskExecutor.getStuckSplitTaskIds(splitProcessingDurationThreshold, runningSplitInfo -> true)).isEmpty();
assertThat(taskExecutor.getRunAwaySplitCount()).isEqualTo(0);
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public void testContainsAndRemove()
for (int i = 1; i < 100; i += 2) {
assertThat(queue.contains("test" + i)).isTrue();
}
assertThat(queue.isEmpty()).isFalse();
assertThat(queue.size()).isEqualTo(50);
assertThat(queue).isNotEmpty();
assertThat(queue).hasSize(50);
for (int i = 1; i < 100; i += 2) {
assertThat(queue.remove("test" + i)).isTrue();
}
assertThat(queue.isEmpty()).isTrue();
assertThat(queue.size()).isEqualTo(0);
assertThat(queue).isEmpty();
assertThat(queue).hasSize(0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testSingleNode()
assertThat(result.isFinished()).isTrue();
assertThat(result.getBlocked().isDone()).isTrue();
assertThat(result.getNewTasks().size()).isEqualTo(1);
assertThat(result.getNewTasks().iterator().next().getNodeId().equals("other 0")).isTrue();
assertThat(result.getNewTasks().iterator().next().getNodeId()).isEqualTo("other 0");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testExcludesCurrentNode()
assertThat(detector.getTotalCount()).isEqualTo(0);
assertThat(detector.getActiveCount()).isEqualTo(0);
assertThat(detector.getFailedCount()).isEqualTo(0);
assertThat(detector.getFailed().isEmpty()).isTrue();
assertThat(detector.getFailed()).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void testInformationSchemaPredicatePushdownOnCatalogWiseTables()
InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle)
metadata.getTableHandle(session, new SchemaTableName("information_schema", "schemata"), Optional.empty(), Optional.empty());
Optional<ConstraintApplicationResult<ConnectorTableHandle>> result = metadata.applyFilter(session, tableHandle, constraint);
assertThat(result.isPresent()).isFalse();
assertThat(result).isEmpty();
}

@Test
Expand Down
Loading