org.junit.contrib.java.lang.system.Assertion Java Examples

The following examples show how to use org.junit.contrib.java.lang.system.Assertion. 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: DenominatorTest.java    From denominator with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidEnvProxySettings() {
  exit.expectSystemExitWithStatus(1);
  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      assertThat(System.getProperty("http.proxyHost")).isEqualTo("localhost");
      assertThat(System.getProperty("http.proxyPort")).isEqualTo("80");
      assertThat(System.getProperty("https.proxyHost")).isNull();
      assertThat(System.getProperty("https.proxyPort")).isNull();
      assertThat(systemErrRule.getLog())
          .isEqualToIgnoringCase(
              "invalid https proxy configuration: no protocol: 10.0.0.1:8443\n");
    }
  });

  Denominator.DenominatorCommand.setProtocolProxyFromEnv("http", "http://localhost");
  Denominator.DenominatorCommand.setProtocolProxyFromEnv("https", "10.0.0.1:8443");
}
 
Example #2
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoCompleteAppCommandScriptFileWillNotOverwrite() throws Exception {
    File dir = new File(System.getProperty("java.io.tmpdir"));
    final File commandScript = new File(dir, "picocli.AutoComplete");
    if (commandScript.exists()) {assertTrue(commandScript.delete());}
    commandScript.deleteOnExit();

    // create the file
    FileOutputStream fous = new FileOutputStream(commandScript, false);
    fous.close();

    File completionScript = new File(dir, commandScript.getName() + "_completion");

    exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_COMMAND_SCRIPT_EXISTS);
    exit.checkAssertionAfterwards(new Assertion() {
        public void checkAssertion() {
            String expected = String.format("" +
                    "ERROR: picocli.AutoComplete: %s exists. Specify --force to overwrite.%n" +
                    "%s", commandScript.getAbsolutePath(), AUTO_COMPLETE_APP_USAGE);
            assertTrue(systemErrRule.getLog().startsWith(expected));
        }
    });
    System.setProperty("picocli.autocomplete.systemExitOnError", "true");
    AutoComplete.main("--writeCommandScript", String.format("-o=%s", completionScript.getAbsolutePath()), "picocli.AutoComplete$App");
}
 
Example #3
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoCompleteAppCommandScriptFileWillOverwriteIfRequested() throws Exception {
    File dir = new File(System.getProperty("java.io.tmpdir"));
    final File commandScript = new File(dir, "picocli.AutoComplete");
    if (commandScript.exists()) {assertTrue(commandScript.delete());}
    commandScript.deleteOnExit();

    // create the file
    FileOutputStream fous = new FileOutputStream(commandScript, false);
    fous.close();
    assertEquals(0, commandScript.length());

    File completionScript = new File(dir, commandScript.getName() + "_completion");

    exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_SUCCESS);
    exit.checkAssertionAfterwards(new Assertion() {
        public void checkAssertion() {
            assertEquals("", systemErrRule.getLog());
            assertNotEquals(0, commandScript.length());
            assertTrue(commandScript.delete());
        }
    });
    System.setProperty("picocli.autocomplete.systemExitOnSuccess", "true");
    AutoComplete.main("--writeCommandScript", "--force", String.format("-o=%s", completionScript.getAbsolutePath()), "picocli.AutoComplete$App");
}
 
Example #4
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoCompleteAppCompletionScriptFileWillNotOverwrite() throws Exception {
    File dir = new File(System.getProperty("java.io.tmpdir"));
    final File completionScript = new File(dir, "App_completion");
    if (completionScript.exists()) {assertTrue(completionScript.delete());}
    completionScript.deleteOnExit();

    // create the file
    FileOutputStream fous = new FileOutputStream(completionScript, false);
    fous.close();

    exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_COMPLETION_SCRIPT_EXISTS);
    exit.checkAssertionAfterwards(new Assertion() {
        public void checkAssertion() {
            String expected = String.format("" +
                    "ERROR: picocli.AutoComplete: %s exists. Specify --force to overwrite.%n" +
                    "%s", completionScript.getAbsolutePath(), AUTO_COMPLETE_APP_USAGE);
            assertTrue(systemErrRule.getLog().startsWith(expected));
        }
    });
    System.setProperty("picocli.autocomplete.systemExitOnError", "");
    AutoComplete.main(String.format("-o=%s", completionScript.getAbsolutePath()), "picocli.AutoComplete$App");
}
 
Example #5
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoCompleteAppCannotInstantiate() {
    @Command(name = "test")
    class TestApp {
        public TestApp(String noDefaultConstructor) { throw new RuntimeException();}
    }

    exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_EXECUTION_ERROR);
    exit.checkAssertionAfterwards(new Assertion() {
        public void checkAssertion() {
            String actual = systemErrRule.getLog();
            assertTrue(actual.startsWith("java.lang.NoSuchMethodException: picocli.AutoCompleteTest$1TestApp.<init>()"));
            assertTrue(actual.contains(AUTO_COMPLETE_APP_USAGE));
        }
    });
    System.setProperty("picocli.autocomplete.systemExitOnSuccess", "false");
    System.setProperty("picocli.autocomplete.systemExitOnError", "YES");
    AutoComplete.main(TestApp.class.getName());
}
 
Example #6
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoCompleteAppGeneratesScriptNameBasedOnCommandName() throws Exception {

    final String commandName = "bestCommandEver";
    final File completionScript = new File(commandName + "_completion");
    if (completionScript.exists()) {assertTrue(completionScript.delete());}
    completionScript.deleteOnExit();

    exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_SUCCESS);
    exit.checkAssertionAfterwards(new Assertion() {
        public void checkAssertion() throws Exception {
            byte[] completion = readBytes(completionScript);
            assertTrue(completionScript.delete());

            String expected = expectedCompletionScriptForAutoCompleteApp().replaceAll("picocli\\.AutoComplete", commandName);
            assertEquals(expected, new String(completion, "UTF8"));
        }
    });
    System.setProperty("picocli.autocomplete.systemExitOnSuccess", "YES");
    AutoComplete.main(String.format("--name=%s", commandName), "picocli.AutoComplete$App");
}
 
Example #7
Source File: CircusTrainHdfsHdfsIntegrationTest.java    From circus-train with Apache License 2.0 6 votes vote down vote up
@Test
public void replicaInSourceMetastore() throws Exception {
  helper.createUnpartitionedTable(toUri(sourceWarehouseUri, DATABASE, UNPARTITIONED_TABLE));
  LOG.info(">>>> Table {} ", sourceCatalog.client().getTable(DATABASE, UNPARTITIONED_TABLE));

  exit.expectSystemExitWithStatus(0);
  File config = dataFolder.getFile("unpartitioned-single-table-same-metastore.yml");
  CircusTrainRunner runner = CircusTrainRunner
      .builder(DATABASE, sourceWarehouseUri, replicaWarehouseUri, housekeepingDbLocation)
      .sourceMetaStore(sourceCatalog.getThriftConnectionUri(), sourceCatalog.connectionURL(),
          sourceCatalog.driverClassName())
      .replicaMetaStore(sourceCatalog.getThriftConnectionUri()) // Override only this value
      .build();
  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      Table hiveTable = sourceCatalog.client().getTable(DATABASE, TARGET_UNPARTITIONED_TABLE);
      assertThat(hiveTable.getDbName(), is(DATABASE));
      assertThat(hiveTable.getTableName(), is(TARGET_UNPARTITIONED_TABLE));
      assertThat(isExternalTable(hiveTable), is(true));
      assertThat(hiveTable.getSd().getCols(), is(DATA_COLUMNS));
    }
  });
  runner.run(config.getAbsolutePath());
}
 
Example #8
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoCompleteAppUsesCustomFactory() throws Exception {

    final String commandName = "nondefault";
    final File completionScript = new File(commandName + "_completion");
    if (completionScript.exists()) {assertTrue(completionScript.delete());}
    completionScript.deleteOnExit();

    exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_SUCCESS);
    exit.checkAssertionAfterwards(new Assertion() {
        public void checkAssertion() throws Exception {
            byte[] completion = readBytes(completionScript);
            assertTrue(completionScript.delete());

            String expected = expectedCompletionScriptForNonDefault().replaceAll("picocli\\.AutoComplete", commandName);
            assertEquals(expected, new String(completion, "UTF8"));
        }
    });
    System.setProperty("picocli.autocomplete.systemExitOnSuccess", "true");
    AutoComplete.main(String.format("--factory=%s", MyFactory.class.getName()),
            String.format("--name=%s", commandName),
            NonDefaultCommand.class.getName());
}
 
Example #9
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void test306_SupportGeneratingAutocompletionScriptForNonPublicCommandClasses() {
    File dir = new File(System.getProperty("java.io.tmpdir"));
    final File completionScript = new File(dir, "App_completion");
    if (completionScript.exists()) {assertTrue(completionScript.delete());}
    completionScript.deleteOnExit();

    exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_SUCCESS);
    exit.checkAssertionAfterwards(new Assertion() {
        public void checkAssertion() {
            assertEquals("", systemErrRule.getLog());
            assertEquals("", systemOutRule.getLog());

            completionScript.delete();
        }
    });
    System.setProperty("picocli.autocomplete.systemExitOnSuccess", "");
    AutoComplete.main(String.format("-o=%s", completionScript.getAbsolutePath()), PrivateCommandClass.class.getName());
}
 
Example #10
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoCompleteAppHelp() {
    String[][] argsList = new String[][] {
            {"-h"},
            {"--help"},
    };
    for (final String[] args : argsList) {
        exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_SUCCESS);
        exit.checkAssertionAfterwards(new Assertion() {
            public void checkAssertion() {
                assertEquals(args[0], AUTO_COMPLETE_APP_USAGE, systemOutRule.getLog());
                systemOutRule.clearLog();
            }
        });
        System.setProperty("picocli.autocomplete.systemExitOnSuccess", "YES");
        AutoComplete.main(args);
    }
}
 
Example #11
Source File: AbstractCommandTest.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
protected void assertCommandLine(int exitCode, Assertion assertion, boolean includeConf,
        String... tokens) throws Exception {
    String[] commandLine = commandLine(includeConf, tokens);
    printCWD();
    System.out.println(">>> " + Constants.command()
            + StringUtils.arrayToDelimitedString(commandLine, " "));
    System.out.println("");
    systemOutRule.clearLog();

    exit.expectSystemExitWithStatus(exitCode);
    exit.checkAssertionAfterwards(assertion);
    try {
        Main.main(commandLine);
    }
    catch (Throwable t) {
        Chalk.setColorEnabled(true);
        throw t;
    }
}
 
Example #12
Source File: JApiCmpTest.java    From japicmp with Apache License 2.0 6 votes vote down vote up
@Test
public void testIgnoreMissingClassesByRegExCouldNotLoad() throws IOException, CannotCompileException {
	exit.expectSystemExitWithStatus(1);
	exit.checkAssertionAfterwards(new Assertion() {
		public void checkAssertion() {
			String errLogTrimmed = errLog.getLog().trim();
			assertThat(errLogTrimmed, containsString("E: Could not load 'NotExistingSuperclass'".trim()));
		}
	});
	ClassPool cp = new ClassPool(true);
	CtClass ctClassSuperclass = CtClassBuilder.create().name("NotExistingSuperclass").addToClassPool(cp);
	CtConstructorBuilder.create().addToClass(ctClassSuperclass);
	CtClass ctClass = CtClassBuilder.create().name("Test").withSuperclass(ctClassSuperclass).addToClassPool(cp);
	Path oldPath = Paths.get(System.getProperty("user.dir"), "target", JApiCmpTest.class.getSimpleName() + "_old.jar");
	createJarFile(oldPath, ctClass);
	Path newPath = Paths.get(System.getProperty("user.dir"), "target", JApiCmpTest.class.getSimpleName() + "_new.jar");
	createJarFile(newPath, ctClass);
	JApiCmp.main(new String[]{"-n", newPath.toString(), "-o", oldPath.toString()});
}
 
Example #13
Source File: JApiCmpTest.java    From japicmp with Apache License 2.0 6 votes vote down vote up
@Test
public void testIgnoreMissingClassesByRegExMissingAreIgnore() throws IOException, CannotCompileException {
	exit.checkAssertionAfterwards(new Assertion() {
		public void checkAssertion() {
			String outLog = JApiCmpTest.this.outLog.getLog().trim();
			assertThat(outLog, containsString("Comparing".trim()));
			assertThat(outLog, containsString("WARNING: You have ignored certain classes".trim()));
		}
	});
	ClassPool cp = new ClassPool(true);
	CtClass ctClassSuperclass = CtClassBuilder.create().name("NotExistingSuperclass").addToClassPool(cp);
	CtConstructorBuilder.create().addToClass(ctClassSuperclass);
	CtClass ctClass = CtClassBuilder.create().name("Test").withSuperclass(ctClassSuperclass).addToClassPool(cp);
	Path oldPath = Paths.get(System.getProperty("user.dir"), "target", JApiCmpTest.class.getSimpleName() + "_old.jar");
	createJarFile(oldPath, ctClass);
	Path newPath = Paths.get(System.getProperty("user.dir"), "target", JApiCmpTest.class.getSimpleName() + "_new.jar");
	createJarFile(newPath, ctClass);
	JApiCmp.main(new String[]{"-n", newPath.toString(), "-o", oldPath.toString(), CliParser.IGNORE_MISSING_CLASSES_BY_REGEX, ".*Superc.*"});
}
 
Example #14
Source File: JApiCmpTest.java    From japicmp with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithOldArchiveOptionButWithoutArgument() {
	exit.expectSystemExitWithStatus(1);
	exit.checkAssertionAfterwards(new Assertion() {
		public void checkAssertion() {
			assertThat(errLog.getLog().trim(), containsString("E: Missing argument for option '-o, --old'.".trim()));
			assertThatUseHelpOptionIsPrinted();
		}
	});
	JApiCmp.main(new String[]{"-o"});
}
 
Example #15
Source File: JApiCmpTest.java    From japicmp with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithNewArchiveOptionButWithInvalidArgument() {
	exit.expectSystemExitWithStatus(1);
	exit.checkAssertionAfterwards(new Assertion() {
		public void checkAssertion() {
			String errLogTrimmed = errLog.getLog().trim();
			assertThat(errLogTrimmed, containsString("E: File".trim()));
			assertThat(errLogTrimmed, containsString("does not exist.".trim()));
			assertThatUseHelpOptionIsPrinted();
		}
	});
	JApiCmp.main(new String[]{"-n", "xyz.jar", "-o", "zyx.jar"});
}
 
Example #16
Source File: JApiCmpTest.java    From japicmp with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithOldArchiveOptionButWithInvalidArgument() {
	exit.expectSystemExitWithStatus(1);
	exit.checkAssertionAfterwards(new Assertion() {
		public void checkAssertion() {
			String errLogTrimmed = errLog.getLog().trim();
			assertThat(errLogTrimmed, containsString("E: File".trim()));
			assertThat(errLogTrimmed, containsString("does not exist.".trim()));
			assertThatUseHelpOptionIsPrinted();
		}
	});
	JApiCmp.main(new String[]{"-n", pathTo("new.jar"), "-o", "xyz.jar"});
}
 
Example #17
Source File: JApiCmpTest.java    From japicmp with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithOldArchiveOptionAndNewArchiveOption() {
	exit.checkAssertionAfterwards(new Assertion() {
		public void checkAssertion() {
			assertThat(errLog.getLog().trim(), not(containsString("E: ".trim())));
		}
	});
	JApiCmp.main(new String[]{"-n", pathTo("new.jar"), "-o", pathTo("old.jar")});
}
 
Example #18
Source File: AutoCompleteTest.java    From picocli with Apache License 2.0 5 votes vote down vote up
@Test
public void testAutoCompleteRequiresCommandLineFQCN() {
    exit.expectSystemExitWithStatus(AutoComplete.EXIT_CODE_INVALID_INPUT);
    exit.checkAssertionAfterwards(new Assertion() {
        public void checkAssertion() {
            String expected = String.format("Missing required parameter: '<commandLineFQCN>'%n") + AUTO_COMPLETE_APP_USAGE;
            assertEquals(expected, systemErrRule.getLog());
        }
    });
    System.setProperty("picocli.autocomplete.systemExitOnError", "true");
    AutoComplete.main();
}
 
Example #19
Source File: JApiCmpTest.java    From japicmp with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithNewArchiveOptionButWithoutArgument() {
	exit.expectSystemExitWithStatus(1);
	exit.checkAssertionAfterwards(new Assertion() {
		public void checkAssertion() {
			assertThat(errLog.getLog().trim(), containsString("E: Missing argument for option '-n, --new'.".trim()));
			assertThatUseHelpOptionIsPrinted();
		}
	});
	JApiCmp.main(new String[]{"-n"});
}
 
Example #20
Source File: JApiCmpTest.java    From japicmp with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithoutArguments() {
	exit.expectSystemExitWithStatus(1);
	exit.checkAssertionAfterwards(new Assertion() {
		public void checkAssertion() {
			assertThat(errLog.getLog().trim(), containsString("E: Required option".trim()));
			assertThatUseHelpOptionIsPrinted();
		}
	});
	JApiCmp.main(new String[]{});
}
 
Example #21
Source File: TailStreamerTests.java    From tailstreamer with MIT License 5 votes vote down vote up
@Test
public void testNoArgumentsExit() {
    exit.expectSystemExitWithStatus(1);
    exit.checkAssertionAfterwards(new Assertion() {
        @Override
        public void checkAssertion() throws Exception {
            Assert.assertEquals(ArgumentProcessor.MESSAGE_NO_FILE_SPECIFIED, stderr.getLog().trim());
        }
    });
    TailStreamer.main();
}
 
Example #22
Source File: DescribeCommandIntegrationTest.java    From rug-cli with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSuccessfulArchiveDescribeYaml() throws Exception {
    assertCommandLine(0, new Assertion() {

        @Override
        public void checkAssertion() throws Exception {
            String sysout = systemOutRule.getLogWithNormalizedLineSeparator();
            String stderr = systemErrRule.getLogWithNormalizedLineSeparator();
            assertTrue(stderr.contains("Loading"));
            assertTrue(sysout.startsWith("---"));
        }
    }, "describe", "archive", "atomist-rugs:spring-boot-rest-service", "--output", "yaml");
}
 
Example #23
Source File: DescribeCommandIntegrationTest.java    From rug-cli with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSuccessfulArchiveDescribeJson() throws Exception {
    assertCommandLine(0, new Assertion() {

        @Override
        public void checkAssertion() throws Exception {
            String sysout = systemOutRule.getLogWithNormalizedLineSeparator();
            String stderr = systemErrRule.getLogWithNormalizedLineSeparator();
            assertTrue(stderr.contains("Loading"));
            assertTrue(sysout.startsWith("{"));
        }
    }, "describe", "archive", "atomist-rugs:spring-boot-rest-service", "--output", "json");
}
 
Example #24
Source File: CircusTrainHdfsHdfsIntegrationTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Test
public void unpartitionedViewWithMappings() throws Exception {
  helper.createManagedUnpartitionedTable(toUri(sourceWarehouseUri, DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE));
  LOG.info(">>>> Table {} ", sourceCatalog.client().getTable(DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE));

  helper.createUnpartitionedView();
  LOG.info(">>>> VIEW {} ", sourceCatalog.client().getTable(DATABASE, SOURCE_UNPARTITIONED_VIEW));

  exit.expectSystemExitWithStatus(0);
  File config = dataFolder.getFile("unpartitioned-single-view-mirror-with-table-mappings.yml");
  CircusTrainRunner runner = CircusTrainRunner
      .builder(DATABASE, sourceWarehouseUri, replicaWarehouseUri, housekeepingDbLocation)
      .sourceMetaStore(sourceCatalog.getThriftConnectionUri(), sourceCatalog.connectionURL(),
          sourceCatalog.driverClassName())
      .replicaMetaStore(replicaCatalog.getThriftConnectionUri())
      .build();
  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      Table hiveView = replicaCatalog.client().getTable(DATABASE, TARGET_UNPARTITIONED_VIEW);
      assertThat(hiveView.getDbName(), is(DATABASE));
      assertThat(hiveView.getTableName(), is(TARGET_UNPARTITIONED_VIEW));
      assertThat(isView(hiveView), is(true));
      assertThat(hiveView.getSd().getCols(), is(DATA_COLUMNS));
      assertThat(hiveView.getViewOriginalText(),
          is(String.format("SELECT * FROM %s.%s", DATABASE, TARGET_UNPARTITIONED_MANAGED_TABLE)));
      assertThat(hiveView.getViewExpandedText(),
          is(String
              .format("SELECT `%s`.`id`, `%s`.`name`, `%s`.`city` FROM `%s`.`%s`", TARGET_UNPARTITIONED_MANAGED_TABLE,
                  TARGET_UNPARTITIONED_MANAGED_TABLE, TARGET_UNPARTITIONED_MANAGED_TABLE, DATABASE,
                  TARGET_UNPARTITIONED_MANAGED_TABLE)));
    }
  });
  runner.run(config.getAbsolutePath());
}
 
Example #25
Source File: CircusTrainHdfsHdfsIntegrationTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Test
public void unpartitionedView() throws Exception {
  helper.createUnpartitionedTable(toUri(sourceWarehouseUri, DATABASE, UNPARTITIONED_TABLE));
  LOG.info(">>>> Table {} ", sourceCatalog.client().getTable(DATABASE, UNPARTITIONED_TABLE));

  helper.createUnpartitionedView();
  LOG.info(">>>> VIEW {} ", sourceCatalog.client().getTable(DATABASE, SOURCE_UNPARTITIONED_VIEW));

  exit.expectSystemExitWithStatus(0);
  File config = dataFolder.getFile("unpartitioned-single-view-mirror.yml");
  CircusTrainRunner runner = CircusTrainRunner
      .builder(DATABASE, sourceWarehouseUri, replicaWarehouseUri, housekeepingDbLocation)
      .sourceMetaStore(sourceCatalog.getThriftConnectionUri(), sourceCatalog.connectionURL(),
          sourceCatalog.driverClassName())
      .replicaMetaStore(replicaCatalog.getThriftConnectionUri())
      .build();
  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      Table hiveView = replicaCatalog.client().getTable(DATABASE, TARGET_UNPARTITIONED_VIEW);
      assertThat(hiveView.getDbName(), is(DATABASE));
      assertThat(hiveView.getTableName(), is(TARGET_UNPARTITIONED_VIEW));
      assertThat(isView(hiveView), is(true));
      assertThat(hiveView.getSd().getCols(), is(DATA_COLUMNS));
    }
  });
  runner.run(config.getAbsolutePath());
}
 
Example #26
Source File: CircusTrainHdfsHdfsIntegrationTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Test
public void partitionedView() throws Exception {
  helper.createPartitionedTable(toUri(sourceWarehouseUri, DATABASE, PARTITIONED_TABLE));
  LOG.info(">>>> Table {} ", sourceCatalog.client().getTable(DATABASE, PARTITIONED_TABLE));

  helper.createPartitionedView();
  LOG.info(">>>> VIEW {} ", sourceCatalog.client().getTable(DATABASE, SOURCE_PARTITIONED_VIEW));

  exit.expectSystemExitWithStatus(0);
  File config = dataFolder.getFile("partitioned-single-view-mirror.yml");
  CircusTrainRunner runner = CircusTrainRunner
      .builder(DATABASE, sourceWarehouseUri, replicaWarehouseUri, housekeepingDbLocation)
      .sourceMetaStore(sourceCatalog.getThriftConnectionUri(), sourceCatalog.connectionURL(),
          sourceCatalog.driverClassName())
      .replicaMetaStore(replicaCatalog.getThriftConnectionUri())
      .build();
  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      Table hiveView = replicaCatalog.client().getTable(DATABASE, TARGET_PARTITIONED_VIEW);
      assertThat(hiveView.getDbName(), is(DATABASE));
      assertThat(hiveView.getTableName(), is(TARGET_PARTITIONED_VIEW));
      assertThat(isView(hiveView), is(true));
      assertThat(hiveView.getSd().getCols(), is(DATA_COLUMNS));
    }
  });
  runner.run(config.getAbsolutePath());
}
 
Example #27
Source File: CircusTrainHdfsHdfsIntegrationTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Test
public void multipleTransformationOverridesApplied() throws Exception {
  helper.createManagedUnpartitionedTable(toUri(sourceWarehouseUri, DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE));
  LOG.info(">>>> Table {} ", sourceCatalog.client().getTable(DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE));

  java.nio.file.Path sourceAvroSchemaPath = Paths.get(sourceWarehouseUri.toString() + "/avro-schema-file.test");
  Files.write(sourceAvroSchemaPath, AVRO_SCHEMA_CONTENT.getBytes());
  String avroSchemaUrl = sourceAvroSchemaPath.toString();

  Table sourceTable = sourceCatalog.client().getTable(DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE);
  sourceTable.putToParameters("avro.schema.url", avroSchemaUrl);
  sourceTable.putToParameters("circus.train.test.transformation", "enabled");
  sourceCatalog.client().alter_table(sourceTable.getDbName(), sourceTable.getTableName(), sourceTable);

  exit.expectSystemExitWithStatus(0);
  File config = dataFolder.getFile("unpartitioned-single-table-multiple-transformation-overrides.yml");
  CircusTrainRunner runner = CircusTrainRunner
      .builder(DATABASE, sourceWarehouseUri, replicaWarehouseUri, housekeepingDbLocation)
      .sourceMetaStore(sourceCatalog.getThriftConnectionUri(), sourceCatalog.connectionURL(),
          sourceCatalog.driverClassName())
      .replicaMetaStore(replicaCatalog.getThriftConnectionUri())
      .build();

  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      Table replicaHiveTable = replicaCatalog.client().getTable(DATABASE, TARGET_UNPARTITIONED_MANAGED_TABLE);
      String expectedReplicaSchemaUrl = replicaWarehouseUri.toURI().toString() + "ct_database/override";
      Map<String, String> parameters = replicaHiveTable.getParameters();
      String transformedAvroUrl = parameters.get("avro.schema.url");
      assertThat(parameters.get("table.property.first"), is("first-override"));
      assertThat(parameters.get("table.property.second"), is("second-override"));
      assertThat(parameters.get("table.transformed"), is("true"));
      assertThat(transformedAvroUrl, startsWith(expectedReplicaSchemaUrl));
    }
  });

  runner.run(config.getAbsolutePath());
}
 
Example #28
Source File: CircusTrainHdfsHdfsIntegrationTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Test
public void multipleTransformationsApplied() throws Exception {
  helper.createManagedUnpartitionedTable(toUri(sourceWarehouseUri, DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE));
  LOG.info(">>>> Table {} ", sourceCatalog.client().getTable(DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE));

  java.nio.file.Path sourceAvroSchemaPath = Paths.get(sourceWarehouseUri.toString() + "/avro-schema-file.test");
  Files.write(sourceAvroSchemaPath, AVRO_SCHEMA_CONTENT.getBytes());
  String avroSchemaUrl = sourceAvroSchemaPath.toString();

  Table sourceTable = sourceCatalog.client().getTable(DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE);
  sourceTable.putToParameters("avro.schema.url", avroSchemaUrl);
  sourceTable.putToParameters("circus.train.test.transformation", "enabled");
  sourceCatalog.client().alter_table(sourceTable.getDbName(), sourceTable.getTableName(), sourceTable);

  exit.expectSystemExitWithStatus(0);
  File config = dataFolder.getFile("unpartitioned-single-table-multiple-transformations.yml");
  CircusTrainRunner runner = CircusTrainRunner
      .builder(DATABASE, sourceWarehouseUri, replicaWarehouseUri, housekeepingDbLocation)
      .sourceMetaStore(sourceCatalog.getThriftConnectionUri(), sourceCatalog.connectionURL(),
          sourceCatalog.driverClassName())
      .replicaMetaStore(replicaCatalog.getThriftConnectionUri())
      .build();

  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      Table replicaHiveTable = replicaCatalog.client().getTable(DATABASE, TARGET_UNPARTITIONED_MANAGED_TABLE);
      String expectedReplicaSchemaUrl = replicaWarehouseUri.toURI().toString() + "ct_database/";
      Map<String, String> parameters = replicaHiveTable.getParameters();
      String transformedAvroUrl = parameters.get("avro.schema.url");
      assertThat(parameters.get("table.property.first"), is("first"));
      assertThat(parameters.get("table.property.second"), is("second"));
      assertThat(parameters.get("table.transformed"), is("true"));
      assertThat(transformedAvroUrl, startsWith(expectedReplicaSchemaUrl));
    }
  });

  runner.run(config.getAbsolutePath());
}
 
Example #29
Source File: CircusTrainHdfsHdfsIntegrationTest.java    From circus-train with Apache License 2.0 5 votes vote down vote up
@Test
public void unpartitionedTableReplicateAvroSchemaOverride() throws Exception {
  helper.createManagedUnpartitionedTable(toUri(sourceWarehouseUri, DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE));
  LOG.info(">>>> Table {} ", sourceCatalog.client().getTable(DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE));

  java.nio.file.Path sourceAvroSchemaPath = Paths.get(sourceWarehouseUri.toString() + "/avro-schema-file.test");
  Files.write(sourceAvroSchemaPath, AVRO_SCHEMA_CONTENT.getBytes());
  String avroSchemaBaseUrl = sourceAvroSchemaPath.toString();

  Table sourceTable = sourceCatalog.client().getTable(DATABASE, SOURCE_MANAGED_UNPARTITIONED_TABLE);
  sourceTable.putToParameters("avro.schema.url", avroSchemaBaseUrl);
  sourceCatalog.client().alter_table(sourceTable.getDbName(), sourceTable.getTableName(), sourceTable);

  exit.expectSystemExitWithStatus(0);
  File config = dataFolder.getFile("unpartitioned-single-table-avro-schema-override.yml");
  CircusTrainRunner runner = CircusTrainRunner
      .builder(DATABASE, sourceWarehouseUri, replicaWarehouseUri, housekeepingDbLocation)
      .sourceMetaStore(sourceCatalog.getThriftConnectionUri(), sourceCatalog.connectionURL(),
          sourceCatalog.driverClassName())
      .replicaMetaStore(replicaCatalog.getThriftConnectionUri())
      .build();

  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      Table replicaHiveTable = replicaCatalog.client().getTable(DATABASE, TARGET_UNPARTITIONED_MANAGED_TABLE);
      String expectedReplicaSchemaUrl = replicaWarehouseUri.toURI().toString() + "ct_database-override/";
      String transformedAvroUrl = replicaHiveTable.getParameters().get("avro.schema.url");
      assertThat(transformedAvroUrl, startsWith(expectedReplicaSchemaUrl));
    }
  });

  runner.run(config.getAbsolutePath());
}
 
Example #30
Source File: TailStreamerTests.java    From tailstreamer with MIT License 5 votes vote down vote up
@Test
public void testMissingFileArgumentExit() {
    exit.expectSystemExitWithStatus(1);
    exit.checkAssertionAfterwards(new Assertion() {
        @Override
        public void checkAssertion() throws Exception {
            Assert.assertEquals(ArgumentProcessor.MESSAGE_NO_FILE_SPECIFIED, stderr.getLog().trim());
        }
    });
    TailStreamer.main("--server.port=8000");        
}