Search in sources :

Example 26 with ResourceLock

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

the class PatternProcessorTest method testGetNextTimeMonthlyReturnsFirstDayOfNextMonth.

@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testGetNextTimeMonthlyReturnsFirstDayOfNextMonth() {
    final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM}.log.gz");
    final Calendar initial = Calendar.getInstance();
    // Oct 15th
    initial.set(2014, Calendar.OCTOBER, 15, 10, 31, 59);
    final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
    // We expect 1st day of next month
    final Calendar expected = Calendar.getInstance();
    expected.set(2014, Calendar.NOVEMBER, 1, 0, 0, 0);
    expected.set(Calendar.MILLISECOND, 0);
    assertEquals(format(expected.getTimeInMillis()), format(actual));
}
Also used : Calendar(java.util.Calendar) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 27 with ResourceLock

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

the class PatternProcessorTest method testGetNextTimeHourlyReturnsFirstMinuteOfNextHour.

@Test
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
public void testGetNextTimeHourlyReturnsFirstMinuteOfNextHour() {
    final PatternProcessor pp = new PatternProcessor("logs/app-%d{yyyy-MM-dd-HH}.log.gz");
    final Calendar initial = Calendar.getInstance();
    // Tue, March 4, 2014, 10:31
    initial.set(2014, Calendar.MARCH, 4, 10, 31, 59);
    final long actual = pp.getNextTime(initial.getTimeInMillis(), 1, false);
    // expect Wed, March 4, 2014, 11:00
    final Calendar expected = Calendar.getInstance();
    expected.set(2014, Calendar.MARCH, 4, 11, 0, 0);
    expected.set(Calendar.MILLISECOND, 0);
    assertEquals(format(expected.getTimeInMillis()), format(actual));
}
Also used : Calendar(java.util.Calendar) Test(org.junit.jupiter.api.Test) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock)

Example 28 with ResourceLock

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

the class SuppressOutputExtensionTest method shouldThrowExceptionOnMissingResourceLock.

@Test
void shouldThrowExceptionOnMissingResourceLock() {
    Events testEvents = EngineTestKit.engine(ENGINE_ID).selectors(selectClass(SuppressOutputExtensionIncorrectUsage.class)).execute().testEvents();
    testEvents.assertThatEvents().haveExactly(1, event(finishedWithFailure(instanceOf(IllegalStateException.class), message(message -> message.contains("SuppressOutputExtension requires `@ResourceLock( Resources.SYSTEM_OUT )` annotation.")))));
}
Also used : Events(org.junit.platform.testkit.engine.Events) ENGINE_ID(org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor.ENGINE_ID) EventConditions.event(org.junit.platform.testkit.engine.EventConditions.event) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiscoverySelectors.selectClass(org.junit.platform.engine.discovery.DiscoverySelectors.selectClass) EventConditions.finishedWithFailure(org.junit.platform.testkit.engine.EventConditions.finishedWithFailure) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock) TestExecutionResultConditions.message(org.junit.platform.testkit.engine.TestExecutionResultConditions.message) Nested(org.junit.jupiter.api.Nested) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TestExecutionResultConditions.instanceOf(org.junit.platform.testkit.engine.TestExecutionResultConditions.instanceOf) EngineTestKit(org.junit.platform.testkit.engine.EngineTestKit) Resources(org.junit.jupiter.api.parallel.Resources) SuppressOutput(org.neo4j.test.rule.SuppressOutput) Events(org.junit.platform.testkit.engine.Events) Test(org.junit.jupiter.api.Test)

Example 29 with ResourceLock

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

the class FulltextIndexProviderTest method indexWithAnalyzerProviderThatThrowsAnExceptionOnStartupWillBeMarkedAsFailedOnStartup.

@ResourceLock("BrokenAnalyzerProvider")
@Test
void indexWithAnalyzerProviderThatThrowsAnExceptionOnStartupWillBeMarkedAsFailedOnStartup() {
    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 throws.
        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.shouldThrow = 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("boom");
        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 30 with ResourceLock

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

the class FulltextIndexProviderTest method indexWithAnalyzerThatThrowsWillNotBeCreated.

@ResourceLock("BrokenAnalyzerProvider")
@Test
void indexWithAnalyzerThatThrowsWillNotBeCreated() {
    BrokenAnalyzerProvider.shouldThrow = true;
    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);
        // Validation must initially prevent this index from being created.
        var e = assertThrows(RuntimeException.class, creator::create);
        assertThat(e.getMessage()).contains("boom");
        // Create the index anyway.
        BrokenAnalyzerProvider.shouldThrow = false;
        creator.create();
        BrokenAnalyzerProvider.shouldThrow = true;
        // The analyzer will now throw 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, 10, TimeUnit.SECONDS));
        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.shouldThrow = 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 throws.
        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)

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