org.apache.logging.log4j.core.config.ConfigurationException Java Examples

The following examples show how to use org.apache.logging.log4j.core.config.ConfigurationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnlimitedResizePolicyTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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);

}
 
Example #2
Source File: JKSCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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));

}
 
Example #3
Source File: AppenderRefFailoverPolicyTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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);

}
 
Example #4
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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();

}
 
Example #5
Source File: JKSCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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));

}
 
Example #6
Source File: PEMCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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));

}
 
Example #7
Source File: BatchEmitterServiceProviderTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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);

}
 
Example #8
Source File: ChronicleMapRetryFailoverPolicyTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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();

}
 
Example #9
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@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();

}
 
Example #10
Source File: UnlimitedResizePolicy.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: JestBulkOperations.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Object createBatchItem(String indexName, ItemSource source) {
    if (source.getSource() instanceof String) {
        return new Index.Builder(source.getSource())
                .index(indexName)
                .type(mappingType)
                .build();
    }
    throw new ConfigurationException("Non String payloads are not supported by this factory. Make sure that proper ClientObjectFactory implementation is configured");
}
 
Example #12
Source File: AsyncBatchDelivery.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncBatchDelivery build() {
    if (clientObjectFactory == null) {
        throw new ConfigurationException("No Elasticsearch client factory [JestHttp|ElasticsearchBulkProcessor] provided for AsyncBatchDelivery");
    }
    return new AsyncBatchDelivery(this);
}
 
Example #13
Source File: ChronicleMapRetryFailoverPolicyTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void builderThrowsIfAverageValueSizeIsTooLow() throws IOException {

    // given
    ChronicleMapRetryFailoverPolicy.Builder builder = createDefaultTestFailoverPolicyBuilder()
            .withAverageValueSize(511);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("averageValueSize must be higher than or equal 1024");

    // when
    builder.build();

}
 
Example #14
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void throwsWhenUsernameIsNull() {

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

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

    // when
    builder.build();

}
 
Example #15
Source File: ChronicleMapRetryFailoverPolicyTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void builderThrowsIfNumberOfEntriesIsTooLow() throws IOException {

    // given
    ChronicleMapRetryFailoverPolicy.Builder builder = createDefaultTestFailoverPolicyBuilder()
            .withNumberOfEntries(2);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("numberOfEntries must be higher than 2");

    // when
    builder.build();

}
 
Example #16
Source File: IndexTemplateTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test(expected = ConfigurationException.class)
public void builderThrowsExceptionWhenNameIsNotSet() {

    // given
    IndexTemplate.Builder builder = createTestIndexTemplateBuilder();
    builder.withName(null);

    // when
    builder.build();
}
 
Example #17
Source File: Log4j2BatchLimitBackoffPolicy.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public final BatchLimitBackoffPolicy build() {

    if (maxBatchesInFlight <= 0) {
        throw new ConfigurationException("maxBatchesInFlight must be higher than 0 for " +
                BatchLimitBackoffPolicy.class.getSimpleName());
    }

    return new Log4j2BatchLimitBackoffPolicy(maxBatchesInFlight);

}
 
Example #18
Source File: PEMCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void builderThrowsIfClientCertPathIsNotConfigured() {

    // given
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No clientCertPath provided");

    // when
    createTestCertInfoBuilder()
            .withClientCertPath(null)
            .build();

}
 
Example #19
Source File: PEMCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void builderThrowsIfCaPathIsNotConfigured() {

    // given
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No caPath provided");

    // when
    createTestCertInfoBuilder()
            .withCaPath(null)
            .build();

}
 
Example #20
Source File: IndexTemplateTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test(expected = ConfigurationException.class)
public void builderThrowsExceptionWhenNeitherPathOrSourceIsSet() {

    // given
    IndexTemplate.Builder builder = createTestIndexTemplateBuilder();
    builder.withPath(null)
            .withSource(null);

    // when
    builder.build();
}
 
Example #21
Source File: PEMCertInfo.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public PEMCertInfo build() {
    if (keyPath == null) {
        throw new ConfigurationException("No keyPath provided for " + PLUGIN_NAME);
    }
    if (clientCertPath == null) {
        throw new ConfigurationException("No clientCertPath provided for " + PLUGIN_NAME);
    }
    if (caPath == null) {
        throw new ConfigurationException("No caPath provided for " + PLUGIN_NAME);
    }
    return new PEMCertInfo(keyPath, keyPassphrase, clientCertPath, caPath);
}
 
Example #22
Source File: ChronicleMapRetryFailoverPolicyTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void builderThrowsIfBatchSizeIsTooLow() throws IOException {

    // given
    ChronicleMapRetryFailoverPolicy.Builder builder = createDefaultTestFailoverPolicyBuilder()
            .withBatchSize(0);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("batchSize must be higher than 0");

    // when
    builder.build();

}
 
Example #23
Source File: BufferedJestHttpObjectFactory.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected void validate() {

            super.validate();

            if (pooledItemSourceFactory == null) {
                throw new ConfigurationException("No PooledItemSourceFactory configured for BufferedJestHttpObjectFactory");
            }
        }
 
Example #24
Source File: JestHttpObjectFactory.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected void validate() {
    if (serverUris == null) {
        throw new ConfigurationException("No serverUris provided for " + JestHttpObjectFactory.class.getSimpleName());
    }
    if (backoffPolicy == null) {
        throw new ConfigurationException("No BackoffPolicy provided for JestHttp");
    }
}
 
Example #25
Source File: BasicCredentials.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public BasicCredentials build() {
    if (username == null) {
        throw new ConfigurationException("No username provided for " + BasicCredentials.PLUGIN_NAME);
    }
    if (password == null) {
        throw new ConfigurationException("No password provided for " + BasicCredentials.PLUGIN_NAME);
    }
    return new BasicCredentials(username, password);
}
 
Example #26
Source File: ElasticsearchAppenderTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void builderFailsLayoutIsNotProvided() {

    // given
    ElasticsearchAppender.Builder builder = createTestElasticsearchAppenderBuilder();
    builder.withLayout(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No layout provided");

    // when
    builder.build();

}
 
Example #27
Source File: JKSCertInfo.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void applyTo(HttpClientConfig.Builder clientConfigBuilder) {

    try (
            FileInputStream keystoreFile = new FileInputStream(new File(keystorePath));
            FileInputStream truststoreFile = new FileInputStream(new File(truststorePath))
    ) {
        KeyStore keyStore = KeyStore.getInstance("jks");
        keyStore.load(keystoreFile, keystorePassword.toCharArray());
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(keyStore, keystorePassword.toCharArray());

        KeyStore trustStore = KeyStore.getInstance("jks");
        trustStore.load(truststoreFile, truststorePassword.toCharArray());

        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(trustStore);

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);

        // TODO: add support for hostname verification modes
        clientConfigBuilder.sslSocketFactory(new SSLConnectionSocketFactory(sslContext));
        clientConfigBuilder.httpsIOSessionStrategy(new SSLIOSessionStrategy(sslContext, new NoopHostnameVerifier()));

    } catch (IOException | GeneralSecurityException e) {
        throw new ConfigurationException(configExceptionMessage, e);
    }
}
 
Example #28
Source File: RollingIndexNameFormatter.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public RollingIndexNameFormatter build() {
    if (indexName == null) {
        throw new ConfigurationException("No indexName provided for RollingIndexName");
    }
    if (pattern == null) {
        throw new ConfigurationException("No pattern provided for RollingIndexName");
    }
    return new RollingIndexNameFormatter(indexName, pattern, getInitTimeInMillis(), TimeZone.getTimeZone(timeZone), separator);
}
 
Example #29
Source File: VirtualProperty.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public VirtualProperty build() {

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

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

    return new VirtualProperty(name, value, dynamic);

}
 
Example #30
Source File: BufferedJestHttpObjectFactoryTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void builderThrowsIfSourceFactoryIsNotProvided() {

    // given
    BufferedJestHttpObjectFactory.Builder builder = createTestObjectFactoryBuilder();
    builder.withItemSourceFactory(null);

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

    // when
    builder.build();

}