Skip to content

Commit

Permalink
Make strict config default for Bootstrap
Browse files Browse the repository at this point in the history
Non-strict config is deprecated.
  • Loading branch information
electrum committed Jul 18, 2021
1 parent 323c229 commit bf70fbc
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
208

- Only bind HTTPS config for HTTP server when HTTPS is enabled.
- Make strict config default for Bootstrap. Non-strict is deprecated.

207

Expand Down
16 changes: 15 additions & 1 deletion bootstrap/src/main/java/io/airlift/bootstrap/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class Bootstrap
private Map<String, String> optionalConfigurationProperties;
private boolean initializeLogging = true;
private boolean quiet;
private boolean strictConfig;
private boolean strictConfig = true;
private boolean requireExplicitBindings = true;

private boolean initialized;
Expand Down Expand Up @@ -139,12 +139,26 @@ public Bootstrap quiet()
return this;
}

/**
* @deprecated non-strict config is deprecated
*/
@Deprecated(forRemoval = true)
public Bootstrap strictConfig()
{
this.strictConfig = true;
return this;
}

/**
* @deprecated non-strict config is deprecated
*/
@Deprecated(forRemoval = true)
public Bootstrap nonStrictConfig()
{
this.strictConfig = false;
return this;
}

@SuppressWarnings("unused")
public Bootstrap requireExplicitBindings(boolean requireExplicitBindings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public void testEnvironmentVariableReplacement()
public void testStrictConfig()
{
Bootstrap bootstrap = new Bootstrap()
.strictConfig()
.setRequiredConfigurationProperty("test-required", "foo");

assertThatThrownBy(bootstrap::initialize)
Expand All @@ -133,11 +132,13 @@ public void testStrictConfig()
new Message("Configuration property 'test-required' was not used")));
}

@SuppressWarnings("removal")
@Test
public void testNonStrictConfig()
{
new Bootstrap()
.setRequiredConfigurationProperty("test-required", "foo")
.nonStrictConfig()
.initialize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class TestConfigurationAwareModule
public void testConfigAvailable()
{
Injector injector = new Bootstrap(new FooModule())
.strictConfig()
.doNotInitializeLogging()
.setRequiredConfigurationProperty("foo.enabled", "true")
.setRequiredConfigurationProperty("bar.enabled", "true")
Expand All @@ -50,7 +49,6 @@ public void testConfigAvailable()
public void testInvalidInstall()
{
Bootstrap bootstrap = new Bootstrap(new BrokenInstallModule())
.strictConfig()
.doNotInitializeLogging();

assertThatThrownBy(bootstrap::initialize).isInstanceOfSatisfying(CreationException.class, e ->
Expand Down Expand Up @@ -82,7 +80,6 @@ protected void setup(Binder binder)
});

Injector injector = new Bootstrap(combined)
.strictConfig()
.doNotInitializeLogging()
.setRequiredConfigurationProperty("foo.enabled", "true")
.setRequiredConfigurationProperty("bar.enabled", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void testExecutorShutdown()
new DiscoveryModule());

Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down
2 changes: 1 addition & 1 deletion docs/add_metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Service
new EventModule(),
new JsonModule(),
new JaxrsModule());
app.strictConfig().initialize();
app.initialize();
}

private Service() {}
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public class Service
new EventModule(),
new JsonModule(),
new JaxrsModule());
app.strictConfig().initialize();
app.initialize();
}

private Service()
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started_explanation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ modules here.
Once the bootstrap instance is created, the Service is started via:

```
app.strictConfig().initialize();
app.initialize();
```
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void testConfigDefaults()
.withConfigDefaults(config -> config.setRequestTimeout(new Duration(33, MINUTES))),
new TraceTokenModule())
.quiet()
.strictConfig()
.initialize();

JettyHttpClient httpClient = (JettyHttpClient) injector.getInstance(Key.get(HttpClient.class, FooClient.class));
Expand All @@ -80,7 +79,6 @@ public void testGlobalFilterBinding()
},
new TraceTokenModule())
.quiet()
.strictConfig()
.initialize();

JettyHttpClient fooClient = (JettyHttpClient) injector.getInstance(Key.get(HttpClient.class, FooClient.class));
Expand Down Expand Up @@ -112,7 +110,6 @@ public void testBindingMultipleFiltersAndClients()
},
new TraceTokenModule())
.quiet()
.strictConfig()
.initialize();

assertFilterCount(injector.getInstance(Key.get(HttpClient.class, FooClient.class)), 3);
Expand All @@ -129,7 +126,6 @@ public void testBindClientWithFilter()
.withTracing(),
new TraceTokenModule())
.quiet()
.strictConfig()
.initialize();

HttpClient httpClient = injector.getInstance(Key.get(HttpClient.class, FooClient.class));
Expand All @@ -142,7 +138,6 @@ public void testWithoutFilters()
Injector injector = new Bootstrap(
binder -> httpClientBinder(binder).bindHttpClient("foo", FooClient.class))
.quiet()
.strictConfig()
.initialize();

assertNotNull(injector.getInstance(Key.get(HttpClient.class, FooClient.class)));
Expand All @@ -156,7 +151,6 @@ public void testAliases()
.withAlias(FooAlias1.class)
.withAliases(ImmutableList.of(FooAlias2.class, FooAlias3.class)))
.quiet()
.strictConfig()
.initialize();

HttpClient client = injector.getInstance(Key.get(HttpClient.class, FooClient.class));
Expand All @@ -173,7 +167,6 @@ public void testBindClientWithAliases()
.withAlias(FooAlias1.class)
.withAlias(FooAlias2.class))
.quiet()
.strictConfig()
.initialize();

HttpClient client = injector.getInstance(Key.get(HttpClient.class, FooClient.class));
Expand All @@ -190,7 +183,6 @@ public void testMultipleClients()
httpClientBinder(binder).bindHttpClient("bar", BarClient.class);
})
.quiet()
.strictConfig()
.initialize();

HttpClient fooClient = injector.getInstance(Key.get(HttpClient.class, FooClient.class));
Expand All @@ -207,7 +199,6 @@ public void testClientShutdown()
httpClientBinder(binder).bindHttpClient("bar", BarClient.class);
})
.quiet()
.strictConfig()
.initialize();

HttpClient fooClient = injector.getInstance(Key.get(HttpClient.class, FooClient.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public void testCanConstructServer()

Injector injector = app
.setRequiredConfigurationProperties(properties)
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand All @@ -151,7 +150,6 @@ public void testHttpServerUri()

Injector injector = app
.setRequiredConfigurationProperties(properties)
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down Expand Up @@ -196,7 +194,6 @@ public void testServer()

Injector injector = app
.setRequiredConfigurationProperties(properties)
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down Expand Up @@ -281,7 +278,6 @@ public void testHttpRequestEvent()

Injector injector = app
.setRequiredConfigurationProperties(properties)
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public void testGuiceInjectionWithoutFilters()
});

Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down Expand Up @@ -191,7 +190,6 @@ public void testGuiceInjectionWithFilters()
});

Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down Expand Up @@ -229,7 +227,6 @@ public void testGuiceInjectionWithResources()
});

Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void setup()
});

Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void setup()

Injector injector = app
.quiet()
.strictConfig()
.initialize();

lifeCycleManager = injector.getInstance(LifeCycleManager.class);
Expand Down
2 changes: 1 addition & 1 deletion sample-server/src/main/java/io/airlift/sample/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void main(String[] args)
new MainModule());

try {
Injector injector = app.strictConfig().initialize();
Injector injector = app.initialize();
injector.getInstance(Announcer.class).start();
}
catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public void setup()
new MainModule());

Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void main(String[] args)
new MainModule());

try {
Injector injector = app.strictConfig().initialize();
Injector injector = app.initialize();
injector.getInstance(Announcer.class).start();
}
catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void setup()
new MainModule());

Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();

Expand Down

0 comments on commit bf70fbc

Please sign in to comment.