Search in sources :

Example 11 with Assert

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;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Condition(org.fest.swing.timing.Condition) GuiQuery(org.fest.swing.edt.GuiQuery) KeymapManager(com.intellij.openapi.keymap.KeymapManager) ComponentDriver(org.fest.swing.driver.ComponentDriver) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) com.intellij.openapi.editor(com.intellij.openapi.editor) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) MouseButton(org.fest.swing.core.MouseButton) GuiActionRunner.execute(org.fest.swing.edt.GuiActionRunner.execute) Strings.quote(org.fest.util.Strings.quote) Keymap(com.intellij.openapi.keymap.Keymap) ArrayList(java.util.ArrayList) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Reflection.method(org.fest.reflect.core.Reflection.method) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Project(com.intellij.openapi.project.Project) TextHitInfo(java.awt.font.TextHitInfo) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JBList(com.intellij.ui.components.JBList) FocusManager(javax.swing.FocusManager) GuiTestUtil(com.intellij.testGuiFramework.framework.GuiTestUtil) TextRange(com.intellij.openapi.util.TextRange) AttributedString(java.text.AttributedString) KeyEvent(java.awt.event.KeyEvent) FileEditor(com.intellij.openapi.fileEditor.FileEditor) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) DialogFixture(org.fest.swing.fixture.DialogFixture) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) InputMethodEvent(java.awt.event.InputMethodEvent) AttributedCharacterIterator(java.text.AttributedCharacterIterator) GuiTask(org.fest.swing.edt.GuiTask) Pause.pause(org.fest.swing.timing.Pause.pause) EditorComponentImpl(com.intellij.openapi.editor.impl.EditorComponentImpl) Robot(org.fest.swing.core.Robot) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) Ref(com.intellij.openapi.util.Ref) javax.swing(javax.swing) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorComponentImpl(com.intellij.openapi.editor.impl.EditorComponentImpl) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 12 with Assert

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);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Assert(org.junit.Assert) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with Assert

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));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Assert(org.junit.Assert) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with Assert

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);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Assert(org.junit.Assert) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) UUID(java.util.UUID) Test(org.junit.Test)

Example 15 with Assert

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());
}
Also used : PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) FailSession(org.apache.cassandra.repair.messages.FailSession) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) Executor(java.util.concurrent.Executor) Assert(org.junit.Assert) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List) InetAddress(java.net.InetAddress) RepairSessionResult(org.apache.cassandra.repair.RepairSessionResult) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Aggregations

Assert (org.junit.Assert)18 Test (org.junit.Test)14 List (java.util.List)7 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)5 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)5 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 SSTableAddedNotification (org.apache.cassandra.notifications.SSTableAddedNotification)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Project (com.intellij.openapi.project.Project)2 Ref (com.intellij.openapi.util.Ref)2 InetAddress (java.net.InetAddress)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Set (java.util.Set)2