private <T extends Throwable> void assertThrows(Class<T> throwableClass, ThrowingRunnable runnable, String message) { try { Assert.assertThrows(throwableClass, runnable); } catch (AssertionError e) { throw new AssertionError(String.format("%s%n%s", ((null != message) ? message : ""), e.getMessage()), e); } }
@Test public void testAssertNext() throws InterruptedException, TimeoutException, IOException { EventBus testBus = TestingEventBuses.getEventBus("TestingEventBusAsserterTest.testHappyPath"); try(final TestingEventBusAsserter asserter = new TestingEventBusAsserter("TestingEventBusAsserterTest.testHappyPath")) { testBus.post(new TestingEventBuses.Event("event1")); testBus.post(new TestingEventBuses.Event("event2")); asserter.assertNextValueEq("event1"); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { asserter.assertNextValueEq("event3"); } }); testBus.post(new TestingEventBuses.Event("event13")); testBus.post(new TestingEventBuses.Event("event11")); testBus.post(new TestingEventBuses.Event("event12")); testBus.post(new TestingEventBuses.Event("event10")); asserter.assertNextValuesEq(Arrays.asList("event10", "event11", "event12", "event13")); testBus.post(new TestingEventBuses.Event("event22")); testBus.post(new TestingEventBuses.Event("event20")); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { asserter.assertNextValuesEq(Arrays.asList("event22", "event21")); } }); } }
@Test public void testConfigureFromConfig() { final Config config = ConfigFactory.empty() .withValue(HttpClientConfiguratorLoader.HTTP_CLIENT_CONFIGURATOR_TYPE_KEY, ConfigValueFactory.fromAnyRef("blah")); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { new HttpClientConfiguratorLoader(config); } }); }
@Test public void testConfigAccessor() throws Exception { Config sysConfig1 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder() .put(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, "/tmp") .build()); ImmutableFSJobCatalog.ConfigAccessor cfgAccessor1 = new ImmutableFSJobCatalog.ConfigAccessor(sysConfig1); Assert.assertEquals(cfgAccessor1.getJobConfDir(), "/tmp"); Assert.assertEquals(cfgAccessor1.getJobConfDirPath(), new Path("/tmp")); Assert.assertEquals(cfgAccessor1.getJobConfDirFileSystem().getClass(), FileSystem.get(new Configuration()).getClass()); Assert.assertEquals(cfgAccessor1.getPollingInterval(), ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL); Config sysConfig2 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder() .put(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, "/tmp2") .put(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, 100) .build()); ImmutableFSJobCatalog.ConfigAccessor cfgAccessor2 = new ImmutableFSJobCatalog.ConfigAccessor(sysConfig2); Assert.assertEquals(cfgAccessor2.getJobConfDir(), "file:///tmp2"); Assert.assertEquals(cfgAccessor2.getJobConfDirPath(), new Path("file:///tmp2")); Assert.assertTrue(cfgAccessor2.getJobConfDirFileSystem() instanceof LocalFileSystem); Assert.assertEquals(cfgAccessor2.getPollingInterval(), 100); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { new ImmutableFSJobCatalog.ConfigAccessor(ConfigFactory.empty()); } }); }
@Test public void testMissingOptions() { final Config testConfig1 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder() .put("hadoop-inject.hadoop.security.authentication", "simple") .put("hadoop.loginUser", "foo") .put("gobblin.instance.hadoop.loginUserKeytabFile", "/tmp/bar") .build()); final GobblinInstanceDriver instance1 = Mockito.mock(GobblinInstanceDriver.class); Mockito.when(instance1.getSysConfig()).thenReturn(DefaultConfigurableImpl.createFromConfig(testConfig1)); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { (new HadoopKerberosKeytabAuthenticationPlugin.ConfigBasedFactory()).createPlugin(instance1); } }); final Config testConfig2 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder() .put("hadoop-inject.hadoop.security.authentication", "simple") .put("gobblin.instance.hadoop.loginUser", "foo") .put("hadoop.loginUserKeytabFile", "/tmp/bar") .build()); final GobblinInstanceDriver instance2 = Mockito.mock(GobblinInstanceDriver.class); Mockito.when(instance1.getSysConfig()).thenReturn(DefaultConfigurableImpl.createFromConfig(testConfig2)); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { (new HadoopKerberosKeytabAuthenticationPlugin.ConfigBasedFactory()).createPlugin(instance2); } }); }
private void assertThrowsNPE(ThrowingRunnable r) { assertThrows(NullPointerException.class, r); }
void assertThrowsNPE(ThrowingRunnable r) { assertThrows(NullPointerException.class, r); }
void assertThrowsAIOOB(ThrowingRunnable r) { assertThrows(ArrayIndexOutOfBoundsException.class, r); }
public static void assertThrowsNPE(ThrowingRunnable r) { assertThrows(NullPointerException.class, r); }
private void assertThrowsCCE(ThrowingRunnable r, String s) { assertThrows(ClassCastException.class, r, s); }
private void assertThrowsNPE(ThrowingRunnable r, String s) { assertThrows(NullPointerException.class, r, s); }
private void assertThrowsIAE(ThrowingRunnable r, String s) { assertThrows(IllegalArgumentException.class, r, s); }
private void assertThrowsNSEE(ThrowingRunnable r, String s) { assertThrows(NoSuchElementException.class, r, s); }
private void assertThrowsCME(ThrowingRunnable r) { assertThrows(ConcurrentModificationException.class, r); }