DataStoreCommand implements Command { @Override public void execute(String... args) throws Exception { OptionParser parser = new OptionParser(); opts = new Options(); opts.setCommandName(NAME); opts.setSummary(summary); opts.setConnectionString(CommonOptions.DEFAULT_CONNECTION_STRING); opts.registerOptionsFactory(DataStoreOptions.FACTORY); opts.parseAndConfigure(parser, args); dataStoreOpts = opts.getOptionBean(DataStoreOptions.class); setupDirectories(dataStoreOpts); setupLogging(dataStoreOpts); logCliArgs(args); boolean success = false; try (Closer closer = Utils.createCloserWithShutdownHook()) { opts.setTempDirectory(dataStoreOpts.getWorkDir().getAbsolutePath()); NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts); closer.register(fixture); if (!checkParameters(dataStoreOpts, opts, fixture, parser)) { return; } execute(fixture, dataStoreOpts, opts, closer); success = true; } catch (Throwable e) { log.error("Error occurred while performing datastore operation", e); e.printStackTrace(System.err); } finally { shutdownLogging(); } if (!success) { System.exit(1); } }  @Override void execute(String... args); static void main(String[] args); static final String NAME; }
@Test public void testNoSensitiveParams() throws Exception { storeFixture.close(); File dump = temporaryFolder.newFolder(); List<String> argsList = Lists .newArrayList("--check-consistency", "--" + getOption(blobFixture.getType()), blobFixture.getConfigPath(), "--out-dir", dump.getAbsolutePath(), storeFixture.getConnectionString(), "--reset-log-config", "false", "--work-dir", temporaryFolder.newFolder().getAbsolutePath()); if (!Strings.isNullOrEmpty(additionalParams)) { argsList.add(additionalParams); } log.info("Running testNoSensitiveParams: {}", argsList); LogCustomizer customLogs = LogCustomizer .forLogger(DataStoreCommand.class.getName()) .enable(Level.INFO) .filter(Level.INFO) .matchesRegex(".*mongodb:.*|.*az:.*") .create(); customLogs.starting(); DataStoreCommand cmd = new DataStoreCommand(); try { cmd.execute(argsList.toArray(new String[0])); } catch (Exception e) { log.error("", e); } Assert.assertEquals(0, customLogs.getLogs().size()); customLogs.finished(); }
@Test public void testConsistencyFakeDS() throws Exception { Assume.assumeTrue(storeFixture instanceof StoreFixture.SegmentStoreFixture); File dump = temporaryFolder.newFolder(); File dsPath = temporaryFolder.newFolder(); Data data = prepareData(storeFixture, blobFixture, 10, 5, 0); storeFixture.close(); List<String> argsList = Lists .newArrayList("--check-consistency", "--fake-ds-path", dsPath.getAbsolutePath(), storeFixture.getConnectionString(), "--out-dir", dump.getAbsolutePath(), "--work-dir", temporaryFolder.newFolder().getAbsolutePath()); if (!Strings.isNullOrEmpty(additionalParams)) { argsList.add(additionalParams); } DataStoreCommand cmd = new DataStoreCommand(); cmd.execute(argsList.toArray(new String[0])); assertFileEquals(dump, "avail-", Sets.newHashSet()); assertFileEquals(dump, "marked-", Sets.difference(data.added, data.deleted)); }