Search in sources :

Example 1 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class AvailabilityGuardTest method givenAccessGuardWith2ConditionsWhenAwaitThenTimeoutAndReturnFalse.

@Test
public void givenAccessGuardWith2ConditionsWhenAwaitThenTimeoutAndReturnFalse() throws Exception {
    // Given
    Log log = mock(Log.class);
    AvailabilityGuard availabilityGuard = new AvailabilityGuard(clock, log);
    availabilityGuard.require(REQUIREMENT_1);
    availabilityGuard.require(REQUIREMENT_2);
    // When
    boolean result = availabilityGuard.isAvailable(1000);
    // Then
    assertThat(result, equalTo(false));
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.Test)

Example 2 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class AvailabilityGuardTest method givenAccessGuardWith2ConditionsWhenGrantTwiceAndDenyOnceAndAwaitThenTimeoutAndReturnFalse.

@Test
public void givenAccessGuardWith2ConditionsWhenGrantTwiceAndDenyOnceAndAwaitThenTimeoutAndReturnFalse() throws Exception {
    // Given
    Log log = mock(Log.class);
    AvailabilityGuard availabilityGuard = new AvailabilityGuard(clock, log);
    availabilityGuard.require(REQUIREMENT_1);
    availabilityGuard.require(REQUIREMENT_2);
    // When
    availabilityGuard.fulfill(REQUIREMENT_1);
    availabilityGuard.fulfill(REQUIREMENT_1);
    availabilityGuard.require(REQUIREMENT_2);
    long start = clock.millis();
    long timeout = 1000;
    boolean result = availabilityGuard.isAvailable(timeout);
    long end = clock.millis();
    // Then
    long waitTime = end - start;
    assertFalse(result);
    assertThat(waitTime, greaterThanOrEqualTo(timeout));
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.Test)

Example 3 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class AvailabilityGuardTest method givenAccessGuardWith2ConditionsWhenGrantOnceAndAwaitThenTimeoutAndReturnFalse.

@Test
public void givenAccessGuardWith2ConditionsWhenGrantOnceAndAwaitThenTimeoutAndReturnFalse() throws Exception {
    // Given
    Log log = mock(Log.class);
    AvailabilityGuard availabilityGuard = new AvailabilityGuard(clock, log);
    availabilityGuard.require(REQUIREMENT_1);
    availabilityGuard.require(REQUIREMENT_2);
    // When
    long start = clock.millis();
    long timeout = 1000;
    availabilityGuard.fulfill(REQUIREMENT_1);
    boolean result = availabilityGuard.isAvailable(timeout);
    long end = clock.millis();
    // Then
    long waitTime = end - start;
    assertFalse(result);
    assertThat(waitTime, greaterThanOrEqualTo(timeout));
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.Test)

Example 4 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class AvailabilityGuardTest method givenAccessGuardWithConditionWhenGrantAndDenyThenNotifyListeners.

@Test
public void givenAccessGuardWithConditionWhenGrantAndDenyThenNotifyListeners() throws Exception {
    // Given
    Log log = mock(Log.class);
    final AvailabilityGuard availabilityGuard = new AvailabilityGuard(clock, log);
    availabilityGuard.require(REQUIREMENT_1);
    final AtomicBoolean notified = new AtomicBoolean();
    AvailabilityGuard.AvailabilityListener availabilityListener = new AvailabilityGuard.AvailabilityListener() {

        @Override
        public void available() {
        }

        @Override
        public void unavailable() {
            notified.set(true);
        }
    };
    availabilityGuard.addListener(availabilityListener);
    // When
    availabilityGuard.fulfill(REQUIREMENT_1);
    availabilityGuard.require(REQUIREMENT_1);
    // Then
    assertThat(notified.get(), equalTo(true));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.Test)

Example 5 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class UnknownAddressMonitorTest method shouldResumeLoggingAfterQuietPeriod.

@Test
public void shouldResumeLoggingAfterQuietPeriod() throws Exception {
    // given
    Log log = mock(Log.class);
    FakeClock clock = testClock();
    UnknownAddressMonitor logger = new UnknownAddressMonitor(log, clock, 1000);
    MemberId to = member(0);
    // when
    logger.logAttemptToSendToMemberWithNoKnownAddress(to);
    clock.forward(20001, MILLISECONDS);
    logger.logAttemptToSendToMemberWithNoKnownAddress(to);
    clock.forward(80001, MILLISECONDS);
    logger.logAttemptToSendToMemberWithNoKnownAddress(to);
    // then
    verify(log, times(3)).info(format("No address found for %s, probably because the member has been shut " + "down.", to));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Log(org.neo4j.logging.Log) FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Aggregations

Log (org.neo4j.logging.Log)165 Test (org.junit.Test)60 NullLog (org.neo4j.logging.NullLog)53 Test (org.junit.jupiter.api.Test)50 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)24 Path (java.nio.file.Path)21 LogProvider (org.neo4j.logging.LogProvider)15 File (java.io.File)13 IOException (java.io.IOException)12 Map (java.util.Map)12 Config (org.neo4j.kernel.configuration.Config)10 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)10 PageCache (org.neo4j.io.pagecache.PageCache)9 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)8 Config (org.neo4j.configuration.Config)7 NullLogProvider (org.neo4j.logging.NullLogProvider)7 HashMap (java.util.HashMap)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)6 BasicContext (org.neo4j.kernel.api.proc.BasicContext)6 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)6