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