@Test public void testExplicitPropertyMappingsSingleMetastore() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("hive.metastore.uri", "thrift://localhost:9083") .put("hive.metastore.username", "presto") .build(); StaticMetastoreConfig expected = new StaticMetastoreConfig() .setMetastoreUris("thrift://localhost:9083") .setMetastoreUsername("presto"); assertFullMapping(properties, expected); assertEquals(expected.getMetastoreUris(), ImmutableList.of(URI.create("thrift://localhost:9083"))); assertEquals(expected.getMetastoreUsername(), "presto"); }
@Test public void testDefaults() { assertRecordedDefaults(recordDefaults(QueryMonitorConfig.class) .setMaxOutputStageJsonSize(new DataSize(16, Unit.MEGABYTE))); }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("jmx.dump-tables", "table1,table\\,with\\,commas") .put("jmx.dump-period", "1s") .put("jmx.max-entries", "100") .build(); JmxConnectorConfig expected = new JmxConnectorConfig() .setDumpTables(ImmutableSet.of("table1", "table,with,commas")) .setDumpPeriod(new Duration(1, TimeUnit.SECONDS)) .setMaxEntries(100); assertFullMapping(properties, expected); assertDeprecatedEquivalence(JmxConnectorConfig.class, properties); } }
@Test public void testDefaults() { ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(ExampleConfig.class) .setMetadata(null)); }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("metadata-uri", "file://test.json") .build(); ExampleConfig expected = new ExampleConfig() .setMetadata(URI.create("file://test.json")); ConfigAssertions.assertFullMapping(properties, expected); } }
@Test public void testRecordedDefaultsFailInvokedExtraMethod() { boolean pass = true; try { PersonConfig config = ConfigAssertions.recordDefaults(PersonConfig.class) .setName("Dain") .setEmail("dain@proofpoint.com") .setPhone(null) .setHomePage(URI.create("http://iq80.com")); // extra non setter method invoked config.hashCode(); ConfigAssertions.assertRecordedDefaults(config); } catch (AssertionError e) { // expected pass = false; assertContains(e.getMessage(), "hashCode()"); } if (pass) { fail("Expected AssertionError"); } }
@Test public void testExplicitPropertyMappingsFailUntestedProperty() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("name", "Jenny") .put("email", "jenny@compuserve.com") .put("phone", "867-5309") .build(); PersonConfig expected = new PersonConfig() .setName("Jenny") .setEmail("jenny@compuserve.com") .setPhone("867-5309"); boolean pass = true; try { ConfigAssertions.assertFullMapping(properties, expected); } catch (AssertionError e) { // expected pass = false; Assertions.assertContains(e.getMessage(), "home-page"); } if (pass) { Assert.fail("Expected AssertionError"); } }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("service-inventory.uri", "fake://server") .put("service-inventory.update-interval", "15m") .build(); ServiceInventoryConfig expected = new ServiceInventoryConfig() .setServiceInventoryUri(URI.create("fake://server")) .setUpdateInterval(new Duration(15, TimeUnit.MINUTES)); ConfigAssertions.assertFullMapping(properties, expected); } }
@Test public void testRecordedDefaults() throws Exception { ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(PersonConfig.class) .setName("Dain") .setEmail("dain@proofpoint.com") .setPhone(null) .setHomePage(URI.create("http://iq80.com"))); }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put(SECURITY_CONFIG_FILE, "/test.json") .put(SECURITY_REFRESH_PERIOD, "1s") .build(); FileBasedAccessControlConfig expected = new FileBasedAccessControlConfig() .setConfigFile("/test.json") .setRefreshPeriod(new Duration(1, TimeUnit.SECONDS)); assertFullMapping(properties, expected); }
@Test public void testDeprecatedPropertiesFailUntestedProperties() { Map<String, String> currentProperties = new ImmutableMap.Builder<String, String>() .put("email", "alice@example.com") .build(); Map<String, String> oldProperties = new ImmutableMap.Builder<String, String>() .put("exchange-id", "alice@example.com") .build(); boolean pass = true; try { ConfigAssertions.assertDeprecatedEquivalence(PersonConfig.class, currentProperties, oldProperties); } catch (AssertionError e) { // expected pass = false; assertContains(e.getMessage(), "notes-id"); } if (pass) { fail("Expected AssertionError"); } }
@Test public void testNoDeprecatedProperties() { Map<String, String> currentProperties = new ImmutableMap.Builder<String, String>() .put("email", "alice@example.com") .put("home-page", "http://example.com") .build(); ConfigAssertions.assertDeprecatedEquivalence(NoDeprecatedConfig.class, currentProperties); }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("http-server.authentication.type", "KERBEROS,PASSWORD") .build(); SecurityConfig expected = new SecurityConfig() .setAuthenticationTypes(ImmutableList.of(KERBEROS, PASSWORD)); ConfigAssertions.assertFullMapping(properties, expected); } }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("resources.reserved-system-memory", "1GB") .build(); ReservedSystemMemoryConfig expected = new ReservedSystemMemoryConfig() .setReservedSystemMemory(new DataSize(1, GIGABYTE)); assertFullMapping(properties, expected); } }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("query.low-memory-killer.policy", "total-reservation-on-blocked-nodes") .put("query.low-memory-killer.delay", "20s") .put("query.max-memory", "2GB") .put("query.max-total-memory", "3GB") .build(); MemoryManagerConfig expected = new MemoryManagerConfig() .setLowMemoryKillerPolicy(TOTAL_RESERVATION_ON_BLOCKED_NODES) .setKillOnOutOfMemoryDelay(new Duration(20, SECONDS)) .setMaxQueryMemory(new DataSize(2, GIGABYTE)) .setMaxQueryTotalMemory(new DataSize(3, GIGABYTE)); assertFullMapping(properties, expected); } }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("proxy.uri", "http://example.net/") .put("proxy.shared-secret-file", "test.secret") .build(); ProxyConfig expected = new ProxyConfig() .setUri(URI.create("http://example.net/")) .setSharedSecretFile(new File("test.secret")); assertFullMapping(properties, expected); } }
@Test public void testRecordedDefaultsFailInvokedDeprecatedSetter() throws MalformedURLException { boolean pass = true; try { ConfigAssertions.assertRecordedDefaults(ConfigAssertions.recordDefaults(PersonConfig.class) .setName("Dain") .setEmail("dain@proofpoint.com") .setPhone(null) .setHomePageUrl(new URL("http://iq80.com"))); } catch (AssertionError e) { // expected pass = false; assertContains(e.getMessage(), "HomePageUrl"); } if (pass) { fail("Expected AssertionError"); } }
@Test public void testExplicitPropertyMappingsFailHasDefaultProperty() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("name", "Dain") .put("email", "jenny@compuserve.com") .put("phone", "867-5309") .put("home-page", "http://example.com") .build(); PersonConfig expected = new PersonConfig() .setName("Jenny") .setEmail("jenny@compuserve.com") .setHomePage(URI.create("http://example.com")) .setPhone("867-5309"); boolean pass = true; try { ConfigAssertions.assertFullMapping(properties, expected); } catch (AssertionError e) { // expected pass = false; assertContains(e.getMessage(), "Name"); } if (pass) { fail("Expected AssertionError"); } }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("service-inventory.uri", "fake://server") .put("service-inventory.update-interval", "15m") .build(); ServiceInventoryConfig expected = new ServiceInventoryConfig() .setServiceInventoryUri(URI.create("fake://server")) .setUpdateInterval(new Duration(15, TimeUnit.MINUTES)); ConfigAssertions.assertFullMapping(properties, expected); } }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("mysql.auto-reconnect", "false") .put("mysql.max-reconnects", "4") .put("mysql.connection-timeout", "4s").build(); MySqlConfig expected = new MySqlConfig() .setAutoReconnect(false) .setMaxReconnects(4) .setConnectionTimeout(new Duration(4, TimeUnit.SECONDS)); assertFullMapping(properties, expected); } }