use of com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent in project couchbase-jvm-clients by couchbase.
the class Core method initGlobalConfig.
/**
* Instructs the client to, if possible, load and initialize the global config.
*
* <p>Since global configs are an "optional" feature depending on the cluster version, if an error happens
* this method will not fail. Rather it will log the exception (with some logic dependent on the type of error)
* and will allow the higher level components to move on where possible.</p>
*/
@Stability.Internal
public void initGlobalConfig() {
long start = System.nanoTime();
configurationProvider.loadAndRefreshGlobalConfig().subscribe(v -> {
}, throwable -> {
InitGlobalConfigFailedEvent.Reason reason = InitGlobalConfigFailedEvent.Reason.UNKNOWN;
if (throwable instanceof UnsupportedConfigMechanismException) {
reason = InitGlobalConfigFailedEvent.Reason.UNSUPPORTED;
} else if (throwable instanceof GlobalConfigNotFoundException) {
reason = InitGlobalConfigFailedEvent.Reason.NO_CONFIG_FOUND;
} else if (throwable instanceof ConfigException) {
if (throwable.getCause() instanceof RequestCanceledException) {
RequestContext ctx = ((RequestCanceledException) throwable.getCause()).context().requestContext();
if (ctx.request().cancellationReason() == CancellationReason.SHUTDOWN) {
reason = InitGlobalConfigFailedEvent.Reason.SHUTDOWN;
}
} else if (throwable.getMessage().contains("NO_ACCESS")) {
reason = InitGlobalConfigFailedEvent.Reason.NO_ACCESS;
}
} else if (throwable instanceof AlreadyShutdownException) {
reason = InitGlobalConfigFailedEvent.Reason.SHUTDOWN;
}
eventBus.publish(new InitGlobalConfigFailedEvent(reason.severity(), Duration.ofNanos(System.nanoTime() - start), context(), reason, throwable));
});
}
use of com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent in project couchbase-jvm-clients by couchbase.
the class CoreTest method ignoresFailedGlobalConfigInitAttempt.
@Test
void ignoresFailedGlobalConfigInitAttempt() {
final ConfigurationProvider configProvider = mock(ConfigurationProvider.class);
when(configProvider.configs()).thenReturn(Flux.empty());
Core core = new Core(ENV, AUTHENTICATOR, SeedNode.LOCALHOST) {
@Override
public ConfigurationProvider createConfigurationProvider() {
return configProvider;
}
};
when(configProvider.loadAndRefreshGlobalConfig()).thenReturn(Mono.error(new GlobalConfigNotFoundException()));
core.initGlobalConfig();
when(configProvider.loadAndRefreshGlobalConfig()).thenReturn(Mono.error(new UnsupportedConfigMechanismException()));
core.initGlobalConfig();
int numRaised = 0;
for (Event event : EVENT_BUS.publishedEvents()) {
if (event instanceof InitGlobalConfigFailedEvent) {
numRaised++;
}
}
assertEquals(2, numRaised);
}
Aggregations