use of org.junit.Assert in project intellij-community by JetBrains.
the class EditorFixture method moveToAndClick.
/**
* Moves the caret to the given caret offset (0-based).
*
* @param offset the character offset.
*/
public EditorFixture moveToAndClick(final int offset, MouseButton button) {
assertThat(offset).isGreaterThanOrEqualTo(0);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
Editor editor = manager.getSelectedTextEditor();
assert editor != null;
VisualPosition visualPosition = editor.offsetToVisualPosition(offset);
Point point = editor.visualPositionToXY(visualPosition);
Component editorComponent = robot.finder().find(editor.getComponent(), component -> component instanceof EditorComponentImpl);
robot.click(editorComponent, point, button, 1);
}
});
return this;
}
use of org.junit.Assert in project cassandra by apache.
the class CompactionStrategyManagerPendingRepairTest method cleanupCompactionFinalized.
/**
* Tests that finalized repairs result in cleanup compaction tasks
* which reclassify the sstables as repaired
*/
@Test
public void cleanupCompactionFinalized() {
UUID repairID = registerSession(cfs, true, true);
LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
SSTableReader sstable = makeSSTable(true);
mutateRepaired(sstable, repairID);
csm.handleNotification(new SSTableAddedNotification(Collections.singleton(sstable)), cfs.getTracker());
LocalSessionAccessor.finalizeUnsafe(repairID);
csm.getForPendingRepair(repairID).forEach(Assert::assertNotNull);
Assert.assertNotNull(pendingContains(repairID, sstable));
Assert.assertTrue(sstable.isPendingRepair());
Assert.assertFalse(sstable.isRepaired());
AbstractCompactionTask compactionTask = csm.getNextBackgroundTask(FBUtilities.nowInSeconds());
Assert.assertNotNull(compactionTask);
Assert.assertSame(PendingRepairManager.RepairFinishedCompactionTask.class, compactionTask.getClass());
// run the compaction
compactionTask.execute(null);
Assert.assertTrue(repairedContains(sstable));
Assert.assertFalse(unrepairedContains(sstable));
csm.getForPendingRepair(repairID).forEach(Assert::assertNull);
// sstable should have pendingRepair cleared, and repairedAt set correctly
long expectedRepairedAt = ActiveRepairService.instance.getParentRepairSession(repairID).getRepairedAt();
Assert.assertFalse(sstable.isPendingRepair());
Assert.assertTrue(sstable.isRepaired());
Assert.assertEquals(expectedRepairedAt, sstable.getSSTableMetadata().repairedAt);
}
use of org.junit.Assert in project cassandra by apache.
the class CompactionStrategyManagerPendingRepairTest method sstableAdded.
/**
* Pending repair strategy should be created when we encounter a new pending id
*/
@Test
public void sstableAdded() {
UUID repairID = registerSession(cfs, true, true);
LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
Assert.assertTrue(csm.pendingRepairs().isEmpty());
SSTableReader sstable = makeSSTable(true);
Assert.assertFalse(sstable.isRepaired());
Assert.assertFalse(sstable.isPendingRepair());
mutateRepaired(sstable, repairID);
Assert.assertFalse(sstable.isRepaired());
Assert.assertTrue(sstable.isPendingRepair());
csm.getForPendingRepair(repairID).forEach(Assert::assertNull);
// add the sstable
csm.handleNotification(new SSTableAddedNotification(Collections.singleton(sstable)), cfs.getTracker());
Assert.assertFalse(repairedContains(sstable));
Assert.assertFalse(unrepairedContains(sstable));
csm.getForPendingRepair(repairID).forEach(Assert::assertNotNull);
Assert.assertTrue(pendingContains(repairID, sstable));
}
use of org.junit.Assert in project cassandra by apache.
the class CompactionStrategyManagerPendingRepairTest method cleanupCompactionFailed.
/**
* Tests that failed repairs result in cleanup compaction tasks
* which reclassify the sstables as unrepaired
*/
@Test
public void cleanupCompactionFailed() {
UUID repairID = registerSession(cfs, true, true);
LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
SSTableReader sstable = makeSSTable(true);
mutateRepaired(sstable, repairID);
csm.handleNotification(new SSTableAddedNotification(Collections.singleton(sstable)), cfs.getTracker());
LocalSessionAccessor.failUnsafe(repairID);
csm.getForPendingRepair(repairID).forEach(Assert::assertNotNull);
Assert.assertNotNull(pendingContains(repairID, sstable));
Assert.assertTrue(sstable.isPendingRepair());
Assert.assertFalse(sstable.isRepaired());
AbstractCompactionTask compactionTask = csm.getNextBackgroundTask(FBUtilities.nowInSeconds());
Assert.assertNotNull(compactionTask);
Assert.assertSame(PendingRepairManager.RepairFinishedCompactionTask.class, compactionTask.getClass());
// run the compaction
compactionTask.execute(null);
Assert.assertFalse(repairedContains(sstable));
Assert.assertTrue(unrepairedContains(sstable));
csm.getForPendingRepair(repairID).forEach(Assert::assertNull);
// sstable should have pendingRepair cleared, and repairedAt set correctly
Assert.assertFalse(sstable.isPendingRepair());
Assert.assertFalse(sstable.isRepaired());
Assert.assertEquals(ActiveRepairService.UNREPAIRED_SSTABLE, sstable.getSSTableMetadata().repairedAt);
}
use of org.junit.Assert in project cassandra by apache.
the class CoordinatorSessionTest method failedPropose.
@Test
public void failedPropose() {
InstrumentedCoordinatorSession coordinator = createInstrumentedSession();
Executor executor = MoreExecutors.directExecutor();
AtomicBoolean repairSubmitted = new AtomicBoolean(false);
SettableFuture<List<RepairSessionResult>> repairFuture = SettableFuture.create();
Supplier<ListenableFuture<List<RepairSessionResult>>> sessionSupplier = () -> {
repairSubmitted.set(true);
return repairFuture;
};
// coordinator sends prepare requests to create local session and perform anticompaction
AtomicBoolean hasFailures = new AtomicBoolean(false);
Assert.assertFalse(repairSubmitted.get());
Assert.assertTrue(coordinator.sentMessages.isEmpty());
ListenableFuture sessionResult = coordinator.execute(executor, sessionSupplier, hasFailures);
for (InetAddress participant : PARTICIPANTS) {
RepairMessage expected = new PrepareConsistentRequest(coordinator.sessionID, COORDINATOR, new HashSet<>(PARTICIPANTS));
assertMessageSent(coordinator, participant, expected);
}
// participants respond to coordinator, and repair begins once all participants have responded with success
Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
coordinator.handlePrepareResponse(PARTICIPANT1, true);
Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
coordinator.handlePrepareResponse(PARTICIPANT2, true);
Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
// set the setRepairing callback to verify the correct state when it's called
Assert.assertFalse(coordinator.setRepairingCalled);
coordinator.onSetRepairing = () -> Assert.assertEquals(PREPARED, coordinator.getState());
coordinator.handlePrepareResponse(PARTICIPANT3, true);
Assert.assertTrue(coordinator.setRepairingCalled);
Assert.assertTrue(repairSubmitted.get());
Assert.assertEquals(ConsistentSession.State.REPAIRING, coordinator.getState());
ArrayList<RepairSessionResult> results = Lists.newArrayList(createResult(coordinator), createResult(coordinator), createResult(coordinator));
coordinator.sentMessages.clear();
repairFuture.set(results);
// propose messages should have been sent once all repair sessions completed successfully
for (InetAddress participant : PARTICIPANTS) {
RepairMessage expected = new FinalizePropose(coordinator.sessionID);
assertMessageSent(coordinator, participant, expected);
}
// finalize commit messages will be sent once all participants respond with a promize to finalize
coordinator.sentMessages.clear();
Assert.assertEquals(ConsistentSession.State.REPAIRING, coordinator.getState());
coordinator.handleFinalizePromise(PARTICIPANT1, true);
Assert.assertEquals(ConsistentSession.State.REPAIRING, coordinator.getState());
Assert.assertFalse(coordinator.failCalled);
coordinator.handleFinalizePromise(PARTICIPANT2, false);
Assert.assertEquals(ConsistentSession.State.FAILED, coordinator.getState());
Assert.assertTrue(coordinator.failCalled);
// additional success messages should be ignored
Assert.assertFalse(coordinator.finalizeCommitCalled);
coordinator.onFinalizeCommit = Assert::fail;
coordinator.handleFinalizePromise(PARTICIPANT3, true);
Assert.assertFalse(coordinator.finalizeCommitCalled);
Assert.assertEquals(ConsistentSession.State.FAILED, coordinator.getState());
// failure messages should have been sent to all participants
for (InetAddress participant : PARTICIPANTS) {
RepairMessage expected = new FailSession(coordinator.sessionID);
assertMessageSent(coordinator, participant, expected);
}
Assert.assertTrue(sessionResult.isDone());
Assert.assertTrue(hasFailures.get());
}
Aggregations