org.apache.commons.cli.PosixParser Java Examples

The following examples show how to use org.apache.commons.cli.PosixParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SendMessageCommandTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute() throws SubCommandException {
    PrintStream out = System.out;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bos));
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t mytopic","-p 'send message test'","-c tagA","-k order-16546745756"};
    CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + sendMessageCommand.commandName(), subargs, sendMessageCommand.buildCommandlineOptions(options), new PosixParser());
    sendMessageCommand.execute(commandLine, options, null);

    subargs = new String[] {"-t mytopic","-p 'send message test'","-c tagA","-k order-16546745756","-b brokera","-i 1"};
    commandLine = ServerUtil.parseCmdLine("mqadmin " + sendMessageCommand.commandName(), subargs, sendMessageCommand.buildCommandlineOptions(options), new PosixParser());
    sendMessageCommand.execute(commandLine, options, null);
    System.setOut(out);
    String s = new String(bos.toByteArray());
    Assert.assertTrue(s.contains("SEND_OK"));
}
 
Example #2
Source File: UpdateTopicSubCommandTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute() {
    UpdateTopicSubCommand cmd = new UpdateTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {
        "-b 127.0.0.1:10911",
        "-t unit-test",
        "-r 8",
        "-w 8",
        "-p 6",
        "-o false",
        "-u false",
        "-s false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('b').trim()).isEqualTo("127.0.0.1:10911");
    assertThat(commandLine.getOptionValue('r').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('w').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('p').trim()).isEqualTo("6");
    assertThat(commandLine.getOptionValue('o').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('u').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("false");
}
 
Example #3
Source File: CliFrontendPackageProgramTest.java    From stratosphere with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonExistingJarFile() {
	try {
		String[] arguments = {"-j", "/some/none/existing/path", "-a", "plenty", "of", "arguments"};
		CommandLine line = new PosixParser().parse(CliFrontend.getProgramSpecificOptions(new Options()), arguments, false);
			
		CliFrontend frontend = new CliFrontend();
		Object result = frontend.buildProgram(line);
		assertTrue(result == null);
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Program caused an exception: " + e.getMessage());
	}
}
 
Example #4
Source File: CliFrontendPackageProgramTest.java    From stratosphere with Apache License 2.0 6 votes vote down vote up
@Test
public void testVariantWithExplicitJarAndNoArgumentsOption() {
	try {
		String[] parameters = {"-j", getTestJarPath(), "some", "program", "arguments"};
		CommandLine line = new PosixParser().parse(CliFrontend.getProgramSpecificOptions(new Options()), parameters, false);
		
		CliFrontend frontend = new CliFrontend();
		Object result = frontend.buildProgram(line);
		assertTrue(result instanceof PackagedProgram);
		
		PackagedProgram prog = (PackagedProgram) result;
		
		Assert.assertArrayEquals(new String[] {"some", "program", "arguments"}, prog.getArguments());
		Assert.assertEquals(TEST_JAR_MAIN_CLASS, prog.getMainClassName());
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Program caused an exception: " + e.getMessage());
	}
}
 
Example #5
Source File: MaxmindDbEnrichmentLoaderTest.java    From metron with Apache License 2.0 6 votes vote down vote up
@Test
public void testCommandLineShortOpts() throws Exception {
  String[] argv = {
      "-g testGeoUrl",
      "-a testAsnUrl",
      "-r /test/remoteDirGeo",
      "-ra", "/test/remoteDirAsn",
      "-t /test/tmpDir",
      "-z test:2181"
  };
  String[] otherArgs = new GenericOptionsParser(argv).getRemainingArgs();

  CommandLine cli = MaxmindDbEnrichmentLoader.GeoEnrichmentOptions.parse(new PosixParser(), otherArgs);
  assertEquals("testGeoUrl", MaxmindDbEnrichmentLoader.GeoEnrichmentOptions.GEO_URL.get(cli).trim());
  assertEquals("testAsnUrl", MaxmindDbEnrichmentLoader.GeoEnrichmentOptions.ASN_URL.get(cli).trim());
  assertEquals("/test/remoteDirGeo", MaxmindDbEnrichmentLoader.GeoEnrichmentOptions.REMOTE_GEO_DIR.get(cli).trim());
  assertEquals("/test/remoteDirAsn", MaxmindDbEnrichmentLoader.GeoEnrichmentOptions.REMOTE_ASN_DIR.get(cli).trim());
  assertEquals("/test/tmpDir", MaxmindDbEnrichmentLoader.GeoEnrichmentOptions.TMP_DIR.get(cli).trim());
  assertEquals("test:2181", MaxmindDbEnrichmentLoader.GeoEnrichmentOptions.ZK_QUORUM.get(cli).trim());
}
 
Example #6
Source File: CliFrontendJobManagerConnectionTest.java    From stratosphere with Apache License 2.0 6 votes vote down vote up
@Test
public void testManualOptionsOverridesConfig() {
	try {
		String[] arguments = {"-m", "10.221.130.22:7788"};
		CommandLine line = new PosixParser().parse(CliFrontend.getJobManagerAddressOption(new Options()), arguments, false);
			
		TestingCliFrontend frontend = new TestingCliFrontend(CliFrontendTestUtils.getConfigDir());
		
		InetSocketAddress address = frontend.getJobManagerAddress(line);
		
		assertNotNull(address);
		assertEquals("10.221.130.22", address.getAddress().getHostAddress());
		assertEquals(7788, address.getPort());
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Program caused an exception: " + e.getMessage());
	}
}
 
Example #7
Source File: ConsumeMessageCommandTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteDefaultWhenPullMessageByQueueGotException() throws SubCommandException, InterruptedException, RemotingException, MQClientException, MQBrokerException, NoSuchFieldException, IllegalAccessException {
    DefaultMQPullConsumer defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    when(defaultMQPullConsumer.pull(any(MessageQueue.class), anyString(), anyLong(), anyInt())).thenThrow(Exception.class);
    Field producerField = ConsumeMessageCommand.class.getDeclaredField("defaultMQPullConsumer");
    producerField.setAccessible(true);
    producerField.set(consumeMessageCommand, defaultMQPullConsumer);

    PrintStream out = System.out;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bos));
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t topic-not-existu", "-n localhost:9876"};
    CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + consumeMessageCommand.commandName(),
        subargs, consumeMessageCommand.buildCommandlineOptions(options), new PosixParser());
    consumeMessageCommand.execute(commandLine, options, null);

    System.setOut(out);
    String s = new String(bos.toByteArray());
    Assert.assertTrue(!s.contains("Consume ok"));
}
 
Example #8
Source File: MesosJobClusterEntrypoint.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	// startup checks and logging
	EnvironmentInformation.logEnvironmentInfo(LOG, MesosJobClusterEntrypoint.class.getSimpleName(), args);
	SignalHandler.register(LOG);
	JvmShutdownSafeguard.installAsShutdownHook(LOG);

	// load configuration incl. dynamic properties
	CommandLineParser parser = new PosixParser();
	CommandLine cmd;
	try {
		cmd = parser.parse(ALL_OPTIONS, args);
	}
	catch (Exception e){
		LOG.error("Could not parse the command-line options.", e);
		System.exit(STARTUP_FAILURE_RETURN_CODE);
		return;
	}

	Configuration dynamicProperties = BootstrapTools.parseDynamicProperties(cmd);
	Configuration configuration = MesosEntrypointUtils.loadConfiguration(dynamicProperties, LOG);

	MesosJobClusterEntrypoint clusterEntrypoint = new MesosJobClusterEntrypoint(configuration, dynamicProperties);

	ClusterEntrypoint.runClusterEntrypoint(clusterEntrypoint);
}
 
Example #9
Source File: CliFrontendPackageProgramTest.java    From stratosphere with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonExistingFileWithoutArguments() {
	try {
		String[] parameters = {"/some/none/existing/path"};
		CommandLine line = new PosixParser().parse(CliFrontend.getProgramSpecificOptions(new Options()), parameters, false);
			
		CliFrontend frontend = new CliFrontend();
		Object result = frontend.buildProgram(line);
		assertTrue(result == null);
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		fail("Program caused an exception: " + e.getMessage());
	}
}
 
Example #10
Source File: ConsumeMessageCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteByConditionWhenPullMessageByQueueGotException() throws IllegalAccessException, InterruptedException, RemotingException, MQClientException, MQBrokerException, NoSuchFieldException, SubCommandException {
    DefaultMQPullConsumer defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    when(defaultMQPullConsumer.pull(any(MessageQueue.class), anyString(), anyLong(), anyInt())).thenThrow(Exception.class);
    Field producerField = ConsumeMessageCommand.class.getDeclaredField("defaultMQPullConsumer");
    producerField.setAccessible(true);
    producerField.set(consumeMessageCommand, defaultMQPullConsumer);

    PrintStream out = System.out;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bos));
    Options options = ServerUtil.buildCommandlineOptions(new Options());

    String[] subargs = new String[] {"-t mytopic", "-b localhost", "-i 0", "-n localhost:9876"};
    CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + consumeMessageCommand.commandName(), subargs, consumeMessageCommand.buildCommandlineOptions(options), new PosixParser());
    consumeMessageCommand.execute(commandLine, options, null);

    System.setOut(out);
    String s = new String(bos.toByteArray());
    Assert.assertTrue(!s.contains("Consume ok"));
}
 
Example #11
Source File: ConsumeMessageCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteDefaultWhenPullMessageByQueueGotException() throws SubCommandException, InterruptedException, RemotingException, MQClientException, MQBrokerException, NoSuchFieldException, IllegalAccessException {
    DefaultMQPullConsumer defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    when(defaultMQPullConsumer.pull(any(MessageQueue.class), anyString(), anyLong(), anyInt())).thenThrow(Exception.class);
    Field producerField = ConsumeMessageCommand.class.getDeclaredField("defaultMQPullConsumer");
    producerField.setAccessible(true);
    producerField.set(consumeMessageCommand, defaultMQPullConsumer);

    PrintStream out = System.out;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bos));
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t topic-not-existu", "-n localhost:9876"};
    CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + consumeMessageCommand.commandName(),
        subargs, consumeMessageCommand.buildCommandlineOptions(options), new PosixParser());
    consumeMessageCommand.execute(commandLine, options, null);

    System.setOut(out);
    String s = new String(bos.toByteArray());
    Assert.assertTrue(!s.contains("Consume ok"));
}
 
Example #12
Source File: TermsDataCommand.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("static-access")
private static CommandLine parse(String[] otherArgs, Writer out) {
  Options options = new Options();
  options.addOption(OptionBuilder.withArgName("startwith").hasArg().withDescription("The value to start with.")
      .create("s"));
  options.addOption(OptionBuilder.withArgName("size").hasArg().withDescription("The number of terms to return.")
      .create("n"));
  options.addOption(OptionBuilder.withDescription("Get the frequency of each term.").create("F"));

  CommandLineParser parser = new PosixParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, otherArgs);
  } catch (ParseException e) {
    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(out, true);
    formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, "terms", null, options, HelpFormatter.DEFAULT_LEFT_PAD,
        HelpFormatter.DEFAULT_DESC_PAD, null, false);
    return null;
  }
  return cmd;
}
 
Example #13
Source File: TopicClusterSubCommandTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    TopicClusterSubCommand cmd = new TopicClusterSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
}
 
Example #14
Source File: TopicRouteSubCommandTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    TopicRouteSubCommand cmd = new TopicRouteSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
}
 
Example #15
Source File: ProctorBuilderArgs.java    From proctor with Apache License 2.0 5 votes vote down vote up
public final void parse(final String[] args) {
    final CommandLineParser parser = new PosixParser();
    try {
        final CommandLine result = parser.parse(options, args);
        extract(result);
    } catch (Exception e) {
        System.err.println("Parameter Error - "+e.getMessage());
        final PrintWriter pw = new PrintWriter(System.err);
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(pw, 80, " ", "", options, 1, 2, "");
        pw.close();
        System.exit(-1);
    }
}
 
Example #16
Source File: ConsumerProgressSubCommandTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ConsumerProgressSubCommand cmd = new ConsumerProgressSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #17
Source File: ProducerConnectionSubCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ProducerConnectionSubCommand cmd = new ProducerConnectionSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-producer-group", "-t unit-test"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #18
Source File: ConsumerConnectionSubCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ConsumerConnectionSubCommand cmd = new ConsumerConnectionSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-consumer-group"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #19
Source File: ConsumerProgressSubCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    ConsumerProgressSubCommand cmd = new ConsumerProgressSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #20
Source File: CloneGroupOffsetCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    System.setProperty(MixAll.NAMESRV_ADDR_PROPERTY, "127.0.0.1:9876");
    CloneGroupOffsetCommand cmd = new CloneGroupOffsetCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs =
            new String[] { "-t qatest_TopicTest", "-g qatest_consumer", "-s 1389098416742", "-f true" };
    final CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs,
        cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #21
Source File: AllocateMQSubCommandTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    AllocateMQSubCommand cmd = new AllocateMQSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test", "-i 127.0.0.1:10911"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue("i").trim()).isEqualTo("127.0.0.1:10911");
}
 
Example #22
Source File: UpdateStatisticsTool.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the commandline arguments, throws IllegalStateException if mandatory arguments are
 * missing.
 * @param args supplied command line arguments
 * @return the parsed command line
 */
CommandLine parseOptions(String[] args) {

    final Options options = getOptions();

    CommandLineParser parser = new PosixParser();
    CommandLine cmdLine = null;
    try {
        cmdLine = parser.parse(options, args);
    } catch (ParseException e) {
        printHelpAndExit("Error parsing command line options: " + e.getMessage(), options);
    }

    if (cmdLine.hasOption(HELP_OPTION.getOpt())) {
        printHelpAndExit(options, 0);
    }

    if (!cmdLine.hasOption(TABLE_NAME_OPTION.getOpt())) {
        throw new IllegalStateException(TABLE_NAME_OPTION.getLongOpt() + " is a mandatory "
                + "parameter");
    }

    if (cmdLine.hasOption(MANAGE_SNAPSHOT_OPTION.getOpt())
            && !cmdLine.hasOption(RUN_FOREGROUND_OPTION.getOpt())) {
        throw new IllegalStateException("Snapshot cannot be managed if job is running in background");
    }

    return cmdLine;
}
 
Example #23
Source File: UpdateBrokerConfigSubCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    UpdateBrokerConfigSubCommand cmd = new UpdateBrokerConfigSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-c default-cluster", "-k topicname", "-v unit_test"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #24
Source File: SingleTransferItemFinderTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUploadDirectoryServerRoot() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--upload", "ftps://test.cyberduck.ch/", System.getProperty("java.io.tmpdir")});

    final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.upload, new Path("/", EnumSet.of(Path.Type.directory)));
    assertFalse(found.isEmpty());
    final Iterator<TransferItem> iter = found.iterator();
    final Local temp = LocalFactory.get(System.getProperty("java.io.tmpdir"));
    assertTrue(temp.getType().contains(Path.Type.directory));
    assertEquals(new TransferItem(new Path("/" + temp.getName(), EnumSet.of(Path.Type.directory)), temp), iter.next());
}
 
Example #25
Source File: AllocateMQSubCommandTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    AllocateMQSubCommand cmd = new AllocateMQSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test", "-i 127.0.0.1:10911"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue("i").trim()).isEqualTo("127.0.0.1:10911");
}
 
Example #26
Source File: DeleteTopicSubCommandTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    DeleteTopicSubCommand cmd = new DeleteTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test", "-c default-cluster"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue("c").trim()).isEqualTo("default-cluster");
}
 
Example #27
Source File: ConfigurationFunctionsTest.java    From metron with Apache License 2.0 5 votes vote down vote up
/**
 * Push configuration values to Zookeeper.
 *
 * @param inputPath The local filesystem path to the configurations.
 * @param zookeeperUrl The URL of Zookeeper.
 * @throws Exception
 */
private static void pushConfigs(String inputPath, String zookeeperUrl) throws Exception {

  String[] args = new String[] {
          "-z", zookeeperUrl,
          "--mode", "PUSH",
          "--input_dir", inputPath
  };
  CommandLine cli = ConfigurationManager.ConfigurationOptions.parse(new PosixParser(), args);

  ConfigurationManager manager = new ConfigurationManager();
  manager.run(cli);
}
 
Example #28
Source File: LoadOptionsTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void testHappyPath() {
  CommandLine cli = LoadOptions.parse(new PosixParser(), new String[] { "-eps", "1000", "-ot","foo"});
  EnumMap<LoadOptions, Optional<Object>> results = LoadOptions.createConfig(cli);
  assertEquals(1000L, results.get(LoadOptions.EPS).get());
  assertEquals("foo", results.get(LoadOptions.OUTPUT_TOPIC).get());
  assertEquals(LoadGenerator.CONSUMER_GROUP, results.get(LoadOptions.CONSUMER_GROUP).get());
  assertEquals(Runtime.getRuntime().availableProcessors(), results.get(LoadOptions.NUM_THREADS).get());
  assertFalse(results.get(LoadOptions.BIASED_SAMPLE).isPresent());
  assertFalse(results.get(LoadOptions.CSV).isPresent());
}
 
Example #29
Source File: ResetOffsetByTimeOldCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    ResetOffsetByTimeOldCommand cmd = new ResetOffsetByTimeOldCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-s 1412131213231", "-f false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('g').trim()).isEqualTo("default-group");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("1412131213231");
}
 
Example #30
Source File: ConsumerProgressSubCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ConsumerProgressSubCommand cmd = new ConsumerProgressSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}