Search in sources :

Example 11 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.

the class CollectionLoggingTest method testSimpleMap.

@Test
@ResourceLock(value = Resources.SYSTEM_PROPERTIES, mode = ResourceAccessMode.READ)
public void testSimpleMap(final LoggerContext context) {
    final Logger logger = context.getLogger(CollectionLoggingTest.class.getName());
    logger.error(System.getProperties());
    final Map<String, String> map = new HashMap<>();
    map.put("MyKey1", "MyValue1");
    map.put("MyKey2", "MyValue2");
    logger.error(new StringMapMessage(map));
    logger.error(map);
// TODO: some assertions
}
Also used : StringMapMessage(org.apache.logging.log4j.message.StringMapMessage) HashMap(java.util.HashMap) Logger(org.apache.logging.log4j.Logger) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 12 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project neo4j by neo4j.

the class FulltextIndexProviderTest method indexWithAnalyzerProviderThatReturnsNullWillBeMarkedAsFailedOnStartup.

@ResourceLock("BrokenAnalyzerProvider")
@Test
void indexWithAnalyzerProviderThatReturnsNullWillBeMarkedAsFailedOnStartup() {
    BrokenAnalyzerProvider.shouldThrow = false;
    BrokenAnalyzerProvider.shouldReturnNull = false;
    try (Transaction tx = db.beginTx()) {
        IndexCreator creator = tx.schema().indexFor(label("Label")).withIndexType(org.neo4j.graphdb.schema.IndexType.FULLTEXT).withIndexConfiguration(Map.of(IndexSetting.fulltext_Analyzer(), BrokenAnalyzerProvider.NAME)).on("prop").withName(NAME);
        // The analyzer no longer returns null.
        creator.create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexOnline(NAME, 1, TimeUnit.MINUTES);
        IndexDefinition index = tx.schema().getIndexByName(NAME);
        Schema.IndexState indexState = tx.schema().getIndexState(index);
        assertThat(indexState).isEqualTo(Schema.IndexState.ONLINE);
    }
    BrokenAnalyzerProvider.shouldReturnNull = true;
    controller.restartDbms();
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = tx.schema().getIndexByName(NAME);
        Schema.IndexState indexState = tx.schema().getIndexState(index);
        assertThat(indexState).isEqualTo(Schema.IndexState.FAILED);
        String indexFailure = tx.schema().getIndexFailure(index);
        assertThat(indexFailure).contains("null");
        index.drop();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        assertThrows(IllegalArgumentException.class, () -> tx.schema().getIndexByName(NAME));
        tx.commit();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Schema(org.neo4j.graphdb.schema.Schema) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 13 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project neo4j by neo4j.

the class FulltextIndexProviderTest method indexWithAnalyzerThatReturnsNullWillNotBeCreated.

@ResourceLock("BrokenAnalyzerProvider")
@Test
void indexWithAnalyzerThatReturnsNullWillNotBeCreated() {
    BrokenAnalyzerProvider.shouldThrow = false;
    BrokenAnalyzerProvider.shouldReturnNull = true;
    try (Transaction tx = db.beginTx()) {
        IndexCreator creator = tx.schema().indexFor(label("Label")).withIndexType(org.neo4j.graphdb.schema.IndexType.FULLTEXT).withIndexConfiguration(Map.of(IndexSetting.fulltext_Analyzer(), BrokenAnalyzerProvider.NAME)).on("prop").withName(NAME);
        // Validation must initially prevent this index from being created.
        var e = assertThrows(RuntimeException.class, creator::create);
        assertThat(e.getMessage()).contains("null");
        // Create the index anyway.
        BrokenAnalyzerProvider.shouldReturnNull = false;
        creator.create();
        BrokenAnalyzerProvider.shouldReturnNull = true;
        // The analyzer will now return null during the index population, and the index should then enter a FAILED state.
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        var e = assertThrows(IllegalStateException.class, () -> tx.schema().awaitIndexOnline(NAME, 1, TimeUnit.MINUTES));
        assertThat(e.getMessage()).contains("FAILED");
        IndexDefinition index = tx.schema().getIndexByName(NAME);
        assertThat(tx.schema().getIndexState(index)).isEqualTo(Schema.IndexState.FAILED);
        index.drop();
        tx.commit();
    }
    BrokenAnalyzerProvider.shouldReturnNull = false;
    try (Transaction tx = db.beginTx()) {
        IndexCreator creator = tx.schema().indexFor(label("Label")).withIndexType(org.neo4j.graphdb.schema.IndexType.FULLTEXT).withIndexConfiguration(Map.of(IndexSetting.fulltext_Analyzer(), BrokenAnalyzerProvider.NAME)).on("prop").withName(NAME);
        // The analyzer no longer returns null.
        creator.create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexOnline(NAME, 1, TimeUnit.MINUTES);
        IndexDefinition index = tx.schema().getIndexByName(NAME);
        Schema.IndexState indexState = tx.schema().getIndexState(index);
        assertThat(indexState).isEqualTo(Schema.IndexState.ONLINE);
    }
    controller.restartDbms();
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = tx.schema().getIndexByName(NAME);
        Schema.IndexState indexState = tx.schema().getIndexState(index);
        assertThat(indexState).isEqualTo(Schema.IndexState.ONLINE);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Schema(org.neo4j.graphdb.schema.Schema) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 14 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.

the class LocalizedMessageFactoryTest method testNewMessageUsingBaseName.

@Test
@ResourceLock(Resources.LOCALE)
public void testNewMessageUsingBaseName() {
    final Locale defaultLocale = Locale.getDefault();
    Locale.setDefault(Locale.US);
    try {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory("MF");
        final String testMsg = "hello_world";
        final Message message = localizedMessageFactory.newMessage(testMsg);
        assertEquals("Hello world.", message.getFormattedMessage());
    } finally {
        Locale.setDefault(defaultLocale);
    }
}
Also used : Locale(java.util.Locale) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 15 with ResourceLock

use of org.junit.jupiter.api.parallel.ResourceLock in project logging-log4j2 by apache.

the class AbstractLoggerTest method testMessageThrows.

@Test
@ResourceLock("log4j2.StatusLogger")
public void testMessageThrows() {
    final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(false);
    logger.error(new TestMessage(() -> {
        throw new IllegalStateException("Oops!");
    }, "Message Format"));
    List<StatusData> statusDatalist = StatusLogger.getLogger().getStatusData();
    StatusData mostRecent = statusDatalist.get(statusDatalist.size() - 1);
    assertEquals(Level.WARN, mostRecent.getLevel());
    assertThat(mostRecent.getFormattedStatus(), containsString("org.apache.logging.log4j.spi.AbstractLogger caught " + "java.lang.IllegalStateException logging TestMessage: Message Format"));
}
Also used : StatusData(org.apache.logging.log4j.status.StatusData) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Aggregations

Test (org.junit.jupiter.api.Test)30 ResourceLock (org.junit.jupiter.api.parallel.ResourceLock)30 Calendar (java.util.Calendar)14 Locale (java.util.Locale)6 Transaction (org.neo4j.graphdb.Transaction)4 IndexCreator (org.neo4j.graphdb.schema.IndexCreator)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 Schema (org.neo4j.graphdb.schema.Schema)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)4 Charset (java.nio.charset.Charset)2 Properties (java.util.Properties)2 Logger (org.apache.logging.log4j.Logger)2 StatusData (org.apache.logging.log4j.status.StatusData)2 HashMap (java.util.HashMap)1 StringMapMessage (org.apache.logging.log4j.message.StringMapMessage)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Nested (org.junit.jupiter.api.Nested)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Resources (org.junit.jupiter.api.parallel.Resources)1