void () { final Random gen = new Random(); int N_TRIES = Timings.adjustAccordingToMySpeed(7000, false); LOG.debug("N_TRIES = " + N_TRIES); DocumentEx document = null; final int N = 100; for (int tryn = 0; tryn < N_TRIES; tryn++) { ((UndoManagerImpl)UndoManager.getInstance(getProject())).flushCurrentCommandMerger(); ((UndoManagerImpl)UndoManager.getGlobalInstance()).flushCurrentCommandMerger(); if (document != null) { ((UndoManagerImpl)UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(document); ((UndoManagerImpl)UndoManager.getGlobalInstance()).clearUndoRedoQueueInTests(document); } if (tryn % 10000 == 0) { LOG.debug("iteration "+tryn); } document = (DocumentEx)EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', N)); final DocumentEx finalDocument = document; WriteCommandAction.runWriteCommandAction(getProject(), () -> { List<Pair<RangeMarker, TextRange>> adds = new ArrayList<>(); List<Pair<RangeMarker, TextRange>> dels = new ArrayList<>(); List<Trinity<Integer, Integer, Integer>> edits = new ArrayList<>(); try { for (int i = 0; i < 30; i++) { int x = gen.nextInt(N); int y = x + gen.nextInt(N - x); RangeMarkerEx r = (RangeMarkerEx)finalDocument.createRangeMarker(x, y); adds.add(Pair.create(r, r.getTextRange())); } for (int i = 0; i < 10; i++) { int offset = gen.nextInt(finalDocument.getTextLength()); if (gen.nextBoolean()) { int length = gen.nextInt(5); edits.add(Trinity.create(offset, 0, length)); insertString(finalDocument, offset, StringUtil.repeatSymbol(' ', length)); } else { int length = gen.nextInt(finalDocument.getTextLength() - offset); edits.add(Trinity.create(offset, length, 0)); deleteString(finalDocument, offset, offset + length); } } List<Pair<RangeMarker, TextRange>> candidates = new ArrayList<>(adds); while (!candidates.isEmpty()) { int size = candidates.size(); int x = gen.nextInt(size); Pair<RangeMarker, TextRange> c = candidates.remove(x); RangeMarkerEx r = (RangeMarkerEx)c.first; assertEquals(size - 1, candidates.size()); dels.add(c); r.dispose(); } } catch (AssertionError e) { printFailingSteps(adds, dels, edits); throw e; } }); } }