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));
}
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));
}
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.")))));
}
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();
}
}
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);
}
}
Aggregations