类org.apache.logging.log4j.core.config.ConfigurationException源码实例Demo

下面列出了怎么用org.apache.logging.log4j.core.config.ConfigurationException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: log4j2-elasticsearch   文件: JKSCertInfoTest.java
@Test
public void builderThrowsIfKeyIsInvalid() throws IOException {

    // given
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(PEMCertInfo.configExceptionMessage);

    File invalidKey = createInvalidKey();

    JKSCertInfo testCertInfo = createTestCertInfoBuilder()
            .withKeystorePath(invalidKey.getAbsolutePath())
            .build();

    // when
    testCertInfo.applyTo(mock(HttpClientFactory.Builder.class));

}
 
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
@Test(expected = ConfigurationException.class)
public void throwsExceptionOnUnresolvedAppender() {

    // given
    Appender appender = mock(Appender.class);
    when(appender.isStarted()).thenReturn(true);
    Configuration configuration = mock(Configuration.class);
    String testAppenderRef = "testAppenderRef";
    when(configuration.getAppender(testAppenderRef)).thenReturn(null);

    FailoverPolicy<String> failoverPolicy = createTestFailoverPolicy(testAppenderRef, configuration);

    String failedMessage = "test failed message";

    // when
    failoverPolicy.deliver(failedMessage);

}
 
@Test
public void increaseThrowsWhenResizeWouldNotTakeAnyEffect() {

    // given
    ResizePolicy policy = UnlimitedResizePolicy.newBuilder().withResizeFactor(0.1).build();

    ItemSourcePool pool = mock(ItemSourcePool.class);
    Integer initialPoolSize = 5;
    when(pool.getInitialSize()).thenReturn(initialPoolSize);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("will not resize given pool");

    // when
    policy.increase(pool);

}
 
@Test
public void lifecycleStartFailsIfNoListenersConfigured() throws IOException {

    // given
    ChronicleMapRetryFailoverPolicy failoverPolicy = createDefaultTestFailoverPolicyBuilder().build();

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(
            RetryListener.class.getSimpleName()
                    + " was not provided for "
                    + ChronicleMapRetryFailoverPolicy.class.getSimpleName()
    );

    // when
    failoverPolicy.start();

}
 
源代码7 项目: log4j2-elasticsearch   文件: JKSCertInfoTest.java
@Test
public void builderThrowsIfKeyIsInvalid() throws IOException {

    // given
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(PEMCertInfo.configExceptionMessage);

    File invalidKey = createInvalidKey();

    JKSCertInfo testCertInfo = createTestCertInfoBuilder()
            .withKeystorePath(invalidKey.getAbsolutePath())
            .build();

    // when
    testCertInfo.applyTo(mock(HttpClientConfig.Builder.class));

}
 
源代码8 项目: log4j2-elasticsearch   文件: PEMCertInfoTest.java
@Test
public void builderThrowsIfCantReadKey() {

    // given
    PEMCertInfo testCertInfo = createTestCertInfoBuilder()
            .withKeyPath(TEST_KEY_PATH_WITH_PASSPHRASE)
            .withKeyPassphrase("")
            .build();

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(PEMCertInfo.configExceptionMessage);

    // when
    testCertInfo.applyTo(mock(HttpClientConfig.Builder.class));

}
 
@Test
public void throwsWhenFoundFactoryWasIncompatible() {

    // given
    BatchEmitterServiceProvider serviceProvider = spy(new BatchEmitterServiceProvider());
    TestBatchEmitterFactory emitterFactory = mock(TestBatchEmitterFactory.class);
    Iterator<BatchEmitterFactory> iterator = new ArrayList<BatchEmitterFactory>() {{
        add(emitterFactory);
    }}.iterator();

    when(mockServiceLoader.iterator()).thenReturn(iterator);

    when(emitterFactory.accepts(Matchers.<Class<TestHttpObjectFactory>>any())).thenReturn(false);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No compatible BatchEmitter implementations");

    // when
    createWithTestValues(serviceProvider);

}
 
/**
 * Attempts to resize given pool.
 * <p>
 * Additional pool size is calculated based on it's {@link ItemSourcePool#getInitialSize()}.
 * <p>
 * Single resize operation will never increase pool's size by more than 100%
 *
 * @param itemSourcePool pool to be resized
 * @throws ConfigurationException when {@code resizeFactor * initialPoolSize == 0}
 * @return true, if resize operation was successful, false otherwise
 */
@Override
public boolean increase(ItemSourcePool itemSourcePool) {

    int initialPoolSize = itemSourcePool.getInitialSize();
    int additionalPoolSize = (int) (initialPoolSize * resizeFactor);

    if (additionalPoolSize == 0) {
        throw new ConfigurationException(String.format("Applying %s with resizeFactor %s will not resize given pool [%s] with initialPoolSize %s",
                ResizePolicy.class.getSimpleName(),
                resizeFactor,
                itemSourcePool.getName(),
                itemSourcePool.getInitialSize()));
    }

    itemSourcePool.incrementPoolSize(additionalPoolSize);

    return true;
}
 
@Override
public void execute(IndexTemplate indexTemplate) {
    try {
        createClient().admin().indices().putTemplate(
                new PutIndexTemplateRequest()
                        .name(indexTemplate.getName())
                        .source(indexTemplate.getSource(), XContentType.JSON)
        );
    } catch (Exception e) {
        throw new ConfigurationException(e.getMessage(), e);
    }
}
 
源代码12 项目: log4j2-elasticsearch   文件: JacksonMixInTest.java
@Test
public void builderThrowsOnNullTargetClass() {

    // given
    JacksonMixIn.Builder builder = createDefaultTestBuilder();
    builder.withTargetClass(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No targetClass provided for " + JacksonMixIn.PLUGIN_NAME);

    // when
    builder.build();

}
 
@Test
public void defaultBatchListenerDoesntThrow() {

    // given
    BulkProcessorObjectFactory factory = createTestObjectFactoryBuilder().build();
    Function<BulkRequest, Boolean> batchListener = factory.createBatchListener(failedPayload -> {
        throw new ConfigurationException("test exception");
    });

    // when
    batchListener.apply(null);

}
 
源代码14 项目: log4j2-elasticsearch   文件: JKSCertInfoTest.java
@Test
public void builderThrowsIfKeystorePathIsNotConfigured() {

    // given
    JKSCertInfo.Builder builder = createTestCertInfoBuilder()
            .withKeystorePath(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No keystorePath provided for " + PLUGIN_NAME);

    // when
    builder.build();

}
 
@Override
public TestHttpObjectFactory build() {
    if (serverUris == null) {
        throw new ConfigurationException("No serverUris provided for JestClientConfig");
    }
    return new TestHttpObjectFactory(Arrays.asList(serverUris.split(";")), connTimeout, readTimeout, maxTotalConnection, defaultMaxTotalConnectionPerRoute, discoveryEnabled);
}
 
源代码16 项目: log4j2-elasticsearch   文件: UriParser.java
public int getPort(String serverUri) {
    try {
        return new URI(serverUri).getPort();
    } catch (URISyntaxException e) {
        throw new ConfigurationException(e);
    }
}
 
@Test
public void throwsWhenUsernameIsNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("username");

    // when
    builder.build();

}
 
@Test
public void throwsWhenPasswordIsNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("password");

    // when
    builder.build();

}
 
@Test(expected = ConfigurationException.class)
public void builderFailsIfServerUrisStringIsNull() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    String serverUris = null;

    // when
    builder.withServerUris(serverUris);
    builder.build();

}
 
源代码20 项目: log4j2-elasticsearch   文件: HCHttpTest.java
@Test
public void builderThrowsIfSourceFactoryIsNotProvided() {

    // given
    HCHttp.Builder builder = createDefaultHttpObjectFactoryBuilder();
    builder.withItemSourceFactory(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No " + PooledItemSourceFactory.class.getSimpleName() + " provided");

    // when
    builder.build();

}
 
@Test
public void builderThrowsIfMaxBatchesInFlightEqualsZero() {

    // given
    Log4j2BatchLimitBackoffPolicy.Builder builder = Log4j2BatchLimitBackoffPolicy.newBuilder()
            .withMaxBatchesInFlight(0);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("maxBatchesInFlight must be higher than 0 for " +
            BatchLimitBackoffPolicy.class.getSimpleName());

    // when
    builder.build();

}
 
源代码22 项目: log4j2-elasticsearch   文件: JKSCertInfoTest.java
@Test
public void builderThrowsIfTruststorePasswordIsSetToNull() {

    // given
    JKSCertInfo.Builder builder= createTestCertInfoBuilder()
            .withTruststorePassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("truststorePassword");

    // when
    builder.build();

}
 
源代码23 项目: log4j2-elasticsearch   文件: XPackAuthTest.java
@Test
public void throwsIfCertInfoNotConfigured() {

    // given
    XPackAuth.Builder builder = createTestBuilder()
            .withCertInfo(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("certInfo");

    // when
    builder.build();

}
 
@Test(expected = ConfigurationException.class)
public void builderThrowsExceptioWhenIndexNameIsNull() {

    // when
    RollingIndexNameFormatter.Builder builder = createRollingIndexNameFormatterBuilder();
    builder.withIndexName(null);

    // then
    builder.build();
}
 
源代码25 项目: log4j2-elasticsearch   文件: ClientSettingTest.java
@Test
public void builderFailsWhenValueIsNull() {

    // given
    ClientSetting.Builder clientSetting = createDefaultTestClientSettingBuilder()
            .withValue(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No value provided for " + ClientSetting.NAME);

    // when
    clientSetting.build();

}
 
源代码26 项目: log4j2-elasticsearch   文件: UriParserTest.java
@Test
public void getHostThrowsOnInvalidUri() {

    // given
    String url = "${";
    UriParser uriParser = new UriParser();

    expectedException.expect(ConfigurationException.class);

    // when
    uriParser.getHost(url);
}
 
源代码27 项目: log4j2-elasticsearch   文件: UriParser.java
public String getHost(String s) {
    try {
        return new URI(s).getHost();
    } catch (URISyntaxException e) {
        throw new ConfigurationException(e);
    }
}
 
源代码28 项目: log4j2-elasticsearch   文件: UriParser.java
public int getPort(String serverUri) {
    try {
        return new URI(serverUri).getPort();
    } catch (URISyntaxException e) {
        throw new ConfigurationException(e);
    }
}
 
源代码29 项目: log4j2-elasticsearch   文件: JKSCertInfoTest.java
@Test
public void builderThrowsIfTruststorePathIsNotConfigured() {

    // given
    JKSCertInfo.Builder builder = createTestCertInfoBuilder()
            .withTruststorePath(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No truststorePath provided for " + PLUGIN_NAME);

    // when
    builder.build();

}
 
源代码30 项目: log4j2-elasticsearch   文件: ClientSetting.java
@Override
public ClientSetting build() {

    if (name == null) {
        throw new ConfigurationException("No name provided for " + NAME);
    }

    if (value == null) {
        throw new ConfigurationException("No value provided for " + NAME);
    }

    return new ClientSetting(name, value);

}
 
 类所在包
 类方法
 同包方法