RevisionsCommand implements Command { private void sweep(RevisionsOptions options, Closer closer) throws IOException { int clusterId = options.getClusterId(); if (clusterId <= 0) { System.err.println("clusterId option is required for " + RevisionsOptions.CMD_SWEEP + " command"); return; } DocumentNodeStoreBuilder<?> builder = createDocumentMKBuilder(options, closer); if (builder == null) { System.err.println("revisions mode only available for DocumentNodeStore"); return; } builder.setCacheSegmentCount(1); DocumentStore store = builder.getDocumentStore(); for (ClusterNodeInfoDocument doc : ClusterNodeInfoDocument.all(store)) { if (doc.getClusterId() == clusterId && doc.isActive()) { System.err.println("cannot sweep revisions for active " + "clusterId " + clusterId); return; } } if (!getRootDocument(store).getLastRev().containsKey(clusterId)) { System.err.println("store does not have changes with " + "clusterId " + clusterId); return; } builder.setReadOnlyMode(); useMemoryBlobStore(builder); DocumentNodeStore ns = builder.build(); closer.register(asCloseable(ns)); MissingLastRevSeeker seeker = builder.createMissingLastRevSeeker(); SweepHelper.sweep(store, new RevisionContextWrapper(ns, clusterId), seeker); }  @Override void execute(String... args);  }
@Test public void sweep() throws Exception { int clusterId = ns.getClusterId(); String output = captureSystemErr(new Sweep(clusterId)); assertThat(output, containsString("cannot sweep revisions for active clusterId")); output = captureSystemErr(new Sweep(0)); assertThat(output, containsString("clusterId option is required")); output = captureSystemErr(new Sweep(99)); assertThat(output, containsString("store does not have changes with clusterId")); ns.dispose(); output = captureSystemOut(new Sweep(clusterId)); assertThat(output, containsString("Revision sweep not needed for clusterId")); MongoConnection c = connectionFactory.getConnection(); assertNotNull(c); DocumentNodeStoreBuilder<?> builder = builderProvider.newBuilder() .setMongoDB(c.getMongoClient(), c.getDBName()); DocumentStore store = builder.getDocumentStore(); UpdateOp op = new UpdateOp(getIdFromPath("/"), false); op.removeMapEntry("_sweepRev", new Revision(0, 0, clusterId)); assertNotNull(store.findAndUpdate(Collection.NODES, op)); output = captureSystemOut(new Sweep(clusterId)); assertThat(output, containsString("Updated sweep revision to")); }