RATIS-399. Move all tests to a new module.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/5c37675f Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/5c37675f Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/5c37675f Branch: refs/heads/master Commit: 5c37675fa38f54a7171b4581ba3148652f7f55c1 Parents: d28b649 Author: Tsz Wo Nicholas Sze <[email protected]> Authored: Tue Nov 13 15:38:23 2018 -0800 Committer: Tsz Wo Nicholas Sze <[email protected]> Committed: Tue Nov 13 15:39:04 2018 -0800 ---------------------------------------------------------------------- pom.xml | 2 + .../java/org/apache/ratis/TestRetryPolicy.java | 42 -- .../org/apache/ratis/util/TestLifeCycle.java | 53 -- .../java/org/apache/ratis/util/TestMinMax.java | 57 -- .../org/apache/ratis/util/TestTimeDuration.java | 84 --- .../apache/ratis/util/TestTimeoutScheduler.java | 210 -------- .../ratis/util/TestTraditionalBinaryPrefix.java | 145 ----- ratis-examples/pom.xml | 15 +- ratis-grpc/pom.xml | 11 - .../ratis/grpc/TestGroupManagementWithGrpc.java | 28 - .../ratis/grpc/TestLeaderElectionWithGrpc.java | 36 -- .../ratis/grpc/TestRaftAsyncWithGrpc.java | 24 - .../ratis/grpc/TestRaftExceptionWithGrpc.java | 25 - .../grpc/TestRaftReconfigurationWithGrpc.java | 36 -- .../ratis/grpc/TestRaftServerWithGrpc.java | 59 --- .../ratis/grpc/TestRaftSnapshotWithGrpc.java | 28 - .../TestRaftStateMachineExceptionWithGrpc.java | 26 - .../org/apache/ratis/grpc/TestRaftStream.java | 311 ----------- .../org/apache/ratis/grpc/TestRaftWithGrpc.java | 110 ---- .../ratis/grpc/TestRetryCacheWithGrpc.java | 115 ---- .../grpc/TestServerInformationWithGrpc.java | 25 - .../ratis/grpc/TestServerRestartWithGrpc.java | 25 - .../grpc/TestStateMachineShutdownWithGrpc.java | 26 - .../ratis/grpc/TestWatchRequestWithGrpc.java | 25 - ratis-grpc/src/test/resources/log4j.properties | 18 - ratis-netty/pom.xml | 11 - .../netty/TestGroupManagementWithNetty.java | 28 - .../netty/TestLeaderElectionWithNetty.java | 35 -- .../ratis/netty/TestRaftExceptionWithNetty.java | 25 - .../netty/TestRaftReconfigurationWithNetty.java | 31 -- .../ratis/netty/TestRaftSnapshotWithNetty.java | 31 -- .../TestRaftStateMachineExceptionWithNetty.java | 25 - .../apache/ratis/netty/TestRaftWithNetty.java | 34 -- .../ratis/netty/TestRetryCacheWithNettyRpc.java | 45 -- .../netty/TestServerInformationWithNetty.java | 25 - .../ratis/netty/TestServerRestartWithNetty.java | 25 - ratis-netty/src/test/resources/log4j.properties | 18 - .../TestRaftServerLeaderElectionTimeout.java | 99 ---- .../ratis/TestRaftServerSlownessDetection.java | 109 ---- .../org/apache/ratis/protocol/TestRaftId.java | 54 -- .../apache/ratis/server/TestRaftLogMetrics.java | 119 ----- .../ratis/server/TestRaftServerConfigKeys.java | 98 ---- .../ratis/server/impl/TestRaftServerJmx.java | 109 ---- .../ratis/server/impl/TestServerState.java | 127 ----- .../TestGroupManagementWithSimulatedRpc.java | 28 - .../TestLeaderElectionWithSimulatedRpc.java | 25 - .../TestRaftExceptionWithSimulation.java | 25 - ...TestRaftReconfigurationWithSimulatedRpc.java | 31 -- .../TestRaftSnapshotWithSimulatedRpc.java | 31 -- ...ftStateMachineExceptionWithSimulatedRpc.java | 25 - .../simulation/TestRaftWithSimulatedRpc.java | 25 - .../TestRetryCacheWithSimulatedRpc.java | 45 -- .../TestServerInformationWithSimulatedRpc.java | 25 - .../TestServerRestartWithSimulatedRpc.java | 25 - .../ratis/server/storage/TestCacheEviction.java | 198 ------- .../ratis/server/storage/TestRaftLogCache.java | 257 --------- .../server/storage/TestRaftLogReadWrite.java | 272 ---------- .../server/storage/TestRaftLogSegment.java | 372 ------------- .../ratis/server/storage/TestRaftStorage.java | 206 -------- .../server/storage/TestSegmentedRaftLog.java | 524 ------------------- .../ratis/statemachine/TestStateMachine.java | 201 ------- .../src/test/resources/log4j.properties | 18 - ratis-test/pom.xml | 92 ++++ .../TestRaftServerLeaderElectionTimeout.java | 99 ++++ .../ratis/TestRaftServerSlownessDetection.java | 109 ++++ .../java/org/apache/ratis/TestRetryPolicy.java | 42 ++ .../ratis/grpc/TestGroupManagementWithGrpc.java | 28 + .../ratis/grpc/TestLeaderElectionWithGrpc.java | 36 ++ .../ratis/grpc/TestRaftAsyncWithGrpc.java | 24 + .../ratis/grpc/TestRaftExceptionWithGrpc.java | 25 + .../grpc/TestRaftReconfigurationWithGrpc.java | 36 ++ .../ratis/grpc/TestRaftServerWithGrpc.java | 59 +++ .../ratis/grpc/TestRaftSnapshotWithGrpc.java | 28 + .../TestRaftStateMachineExceptionWithGrpc.java | 26 + .../org/apache/ratis/grpc/TestRaftStream.java | 311 +++++++++++ .../org/apache/ratis/grpc/TestRaftWithGrpc.java | 110 ++++ .../ratis/grpc/TestRetryCacheWithGrpc.java | 115 ++++ .../grpc/TestServerInformationWithGrpc.java | 25 + .../ratis/grpc/TestServerRestartWithGrpc.java | 25 + .../grpc/TestStateMachineShutdownWithGrpc.java | 26 + .../ratis/grpc/TestWatchRequestWithGrpc.java | 25 + .../netty/TestGroupManagementWithNetty.java | 28 + .../netty/TestLeaderElectionWithNetty.java | 35 ++ .../ratis/netty/TestRaftExceptionWithNetty.java | 25 + .../netty/TestRaftReconfigurationWithNetty.java | 31 ++ .../ratis/netty/TestRaftSnapshotWithNetty.java | 31 ++ .../TestRaftStateMachineExceptionWithNetty.java | 25 + .../apache/ratis/netty/TestRaftWithNetty.java | 34 ++ .../ratis/netty/TestRetryCacheWithNettyRpc.java | 45 ++ .../netty/TestServerInformationWithNetty.java | 25 + .../ratis/netty/TestServerRestartWithNetty.java | 25 + .../org/apache/ratis/protocol/TestRaftId.java | 54 ++ .../apache/ratis/server/TestRaftLogMetrics.java | 119 +++++ .../ratis/server/TestRaftServerConfigKeys.java | 98 ++++ .../ratis/server/impl/TestRaftServerJmx.java | 109 ++++ .../ratis/server/impl/TestServerState.java | 127 +++++ .../TestGroupManagementWithSimulatedRpc.java | 28 + .../TestLeaderElectionWithSimulatedRpc.java | 25 + .../TestRaftExceptionWithSimulation.java | 25 + ...TestRaftReconfigurationWithSimulatedRpc.java | 31 ++ .../TestRaftSnapshotWithSimulatedRpc.java | 31 ++ ...ftStateMachineExceptionWithSimulatedRpc.java | 25 + .../simulation/TestRaftWithSimulatedRpc.java | 25 + .../TestRetryCacheWithSimulatedRpc.java | 45 ++ .../TestServerInformationWithSimulatedRpc.java | 25 + .../TestServerRestartWithSimulatedRpc.java | 25 + .../ratis/server/storage/TestCacheEviction.java | 198 +++++++ .../ratis/server/storage/TestRaftLogCache.java | 257 +++++++++ .../server/storage/TestRaftLogReadWrite.java | 272 ++++++++++ .../server/storage/TestRaftLogSegment.java | 372 +++++++++++++ .../ratis/server/storage/TestRaftStorage.java | 206 ++++++++ .../server/storage/TestSegmentedRaftLog.java | 524 +++++++++++++++++++ .../ratis/statemachine/TestStateMachine.java | 201 +++++++ .../org/apache/ratis/util/TestLifeCycle.java | 53 ++ .../java/org/apache/ratis/util/TestMinMax.java | 57 ++ .../org/apache/ratis/util/TestTimeDuration.java | 84 +++ .../apache/ratis/util/TestTimeoutScheduler.java | 210 ++++++++ .../ratis/util/TestTraditionalBinaryPrefix.java | 145 +++++ ratis-test/src/test/resources/log4j.properties | 18 + 119 files changed, 4941 insertions(+), 4910 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 4558609..811ea18 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,8 @@ <module>ratis-netty</module> <module>ratis-hadoop</module> + <module>ratis-test</module> + <module>ratis-assembly</module> <module>ratis-examples</module> <module>ratis-replicated-map</module> http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-common/src/test/java/org/apache/ratis/TestRetryPolicy.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/test/java/org/apache/ratis/TestRetryPolicy.java b/ratis-common/src/test/java/org/apache/ratis/TestRetryPolicy.java deleted file mode 100644 index d481003..0000000 --- a/ratis-common/src/test/java/org/apache/ratis/TestRetryPolicy.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis; - -import org.apache.ratis.retry.RetryPolicies; -import org.apache.ratis.retry.RetryPolicy; -import org.apache.ratis.util.TimeDuration; -import org.junit.Assert; -import org.junit.Test; - -import java.util.concurrent.TimeUnit; - - - -public class TestRetryPolicy { - - @Test - public void testRetryMultipleTimesWithFixedSleep() { - RetryPolicy retryPolicy = RetryPolicies - .retryUpToMaximumCountWithFixedSleep(2, - TimeDuration.valueOf(1000L, TimeUnit.MILLISECONDS)); - boolean shouldRetry = retryPolicy.shouldRetry(1); - Assert.assertTrue(shouldRetry); - Assert.assertTrue(1000 == retryPolicy.getSleepTime().getDuration()); - Assert.assertFalse(retryPolicy.shouldRetry(2)); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-common/src/test/java/org/apache/ratis/util/TestLifeCycle.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/test/java/org/apache/ratis/util/TestLifeCycle.java b/ratis-common/src/test/java/org/apache/ratis/util/TestLifeCycle.java deleted file mode 100644 index 9782792..0000000 --- a/ratis-common/src/test/java/org/apache/ratis/util/TestLifeCycle.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.util; - -import org.junit.Assert; -import org.junit.Test; - -import static org.apache.ratis.util.LifeCycle.State.*; - -import java.util.*; - -public class TestLifeCycle { - /** - * Test if the successor map and the predecessor map are consistent. - * {@link LifeCycle} uses predecessors to validate transitions - * while this test uses successors. - */ - @Test(timeout = 1000) - public void testIsValid() throws Exception { - final Map<LifeCycle.State, List<LifeCycle.State>> successors - = new EnumMap<>(LifeCycle.State.class); - put(NEW, successors, STARTING, CLOSED); - put(STARTING, successors, NEW, RUNNING, CLOSING, EXCEPTION); - put(RUNNING, successors, CLOSING, PAUSING, EXCEPTION); - put(PAUSING, successors, PAUSED, CLOSING, EXCEPTION); - put(PAUSED, successors, STARTING, CLOSING); - put(EXCEPTION, successors, CLOSING); - put(CLOSING , successors, CLOSED); - put(CLOSED, successors); - - final List<LifeCycle.State> states = Arrays.asList(LifeCycle.State.values()); - states.stream().forEach( - from -> states.forEach( - to -> Assert.assertEquals(from + " -> " + to, - successors.get(from).contains(to), - isValid(from, to)))); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-common/src/test/java/org/apache/ratis/util/TestMinMax.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/test/java/org/apache/ratis/util/TestMinMax.java b/ratis-common/src/test/java/org/apache/ratis/util/TestMinMax.java deleted file mode 100644 index 8d315b7..0000000 --- a/ratis-common/src/test/java/org/apache/ratis/util/TestMinMax.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.util; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; -import java.util.OptionalLong; -import java.util.concurrent.ThreadLocalRandom; -import java.util.stream.LongStream; - -public class TestMinMax { - @Test(timeout = 1000) - public void testMinMax() { - runTestMinMax(LongStream.empty()); - runTestMinMax(LongStream.iterate(0, n -> n).limit(10)); - for(int count = 1; count < 10; count++) { - runTestMinMax(LongStream.iterate(1, n -> n + 1).limit(count)); - } - for(int count = 1; count < 10; count++) { - runTestMinMax(LongStream.iterate(0, _dummy -> ThreadLocalRandom.current().nextLong()).limit(count)); - } - } - - static void runTestMinMax(LongStream stream) { - final List<Long> list = stream.collect(ArrayList::new, List::add, List::addAll); - final LongMinMax longMinMax = toLongStream(list).collect(LongMinMax::new, LongMinMax::accumulate, LongMinMax::combine); - if (longMinMax.isInitialized()) { - Assert.assertEquals(toLongStream(list).min().getAsLong(), longMinMax.getMin()); - Assert.assertEquals(toLongStream(list).max().getAsLong(), longMinMax.getMax()); - } else { - Assert.assertEquals(OptionalLong.empty(), toLongStream(list).min()); - Assert.assertEquals(OptionalLong.empty(), toLongStream(list).max()); - } - } - - static LongStream toLongStream(List<Long> list) { - return list.stream().mapToLong(Long::longValue); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-common/src/test/java/org/apache/ratis/util/TestTimeDuration.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/test/java/org/apache/ratis/util/TestTimeDuration.java b/ratis-common/src/test/java/org/apache/ratis/util/TestTimeDuration.java deleted file mode 100644 index 06d9301..0000000 --- a/ratis-common/src/test/java/org/apache/ratis/util/TestTimeDuration.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.util; - -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import static org.apache.ratis.util.TimeDuration.Abbreviation; -import static org.apache.ratis.util.TimeDuration.parse; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class TestTimeDuration { - @Test(timeout = 1000) - public void testTimeDuration() throws Exception { - Arrays.asList(TimeUnit.values()) - .forEach(a -> assertNotNull(Abbreviation.valueOf(a.name()))); - assertEquals(TimeUnit.values().length, Abbreviation.values().length); - - final List<String> allSymbols = Arrays.asList(Abbreviation.values()).stream() - .map(Abbreviation::getSymbols) - .flatMap(List::stream) - .collect(Collectors.toList()); - Arrays.asList(TimeUnit.values()).forEach(unit -> - allSymbols.stream() - .map(s -> "0" + s) - .forEach(s -> assertEquals(s, 0L, parse(s, unit)))); - - assertEquals(1L, parse("1000000 ns", TimeUnit.MILLISECONDS)); - assertEquals(10L, parse("10000000 nanos", TimeUnit.MILLISECONDS)); - assertEquals(100L, parse("100000000 nanosecond", TimeUnit.MILLISECONDS)); - assertEquals(1000L, parse("1000000000 nanoseconds", TimeUnit.MILLISECONDS)); - - assertEquals(1L, parse("1000 us", TimeUnit.MILLISECONDS)); - assertEquals(10L, parse("10000 μs", TimeUnit.MILLISECONDS)); - assertEquals(100L, parse("100000 micros", TimeUnit.MILLISECONDS)); - assertEquals(1000L, parse("1000000 microsecond", TimeUnit.MILLISECONDS)); - assertEquals(10000L, parse("10000000 microseconds", TimeUnit.MILLISECONDS)); - - assertEquals(1L, parse("1 ms", TimeUnit.MILLISECONDS)); - assertEquals(10L, parse("10 msec", TimeUnit.MILLISECONDS)); - assertEquals(100L, parse("100 millis", TimeUnit.MILLISECONDS)); - assertEquals(1000L, parse("1000 millisecond", TimeUnit.MILLISECONDS)); - assertEquals(10000L, parse("10000 milliseconds", TimeUnit.MILLISECONDS)); - - assertEquals(1000L, parse("1 s", TimeUnit.MILLISECONDS)); - assertEquals(10000L, parse("10 sec", TimeUnit.MILLISECONDS)); - assertEquals(100000L, parse("100 second", TimeUnit.MILLISECONDS)); - assertEquals(1000000L, parse("1000 seconds", TimeUnit.MILLISECONDS)); - - assertEquals(60, parse("1 m", TimeUnit.SECONDS)); - assertEquals(600, parse("10 min", TimeUnit.SECONDS)); - assertEquals(6000, parse("100 minutes", TimeUnit.SECONDS)); - assertEquals(60000, parse("1000 minutes", TimeUnit.SECONDS)); - - assertEquals(60, parse("1 h", TimeUnit.MINUTES)); - assertEquals(600, parse("10 hr", TimeUnit.MINUTES)); - assertEquals(6000, parse("100 hour", TimeUnit.MINUTES)); - assertEquals(60000, parse("1000 hours", TimeUnit.MINUTES)); - - assertEquals(24, parse("1 d", TimeUnit.HOURS)); - assertEquals(240, parse("10 day", TimeUnit.HOURS)); - assertEquals(2400, parse("100 days", TimeUnit.HOURS)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-common/src/test/java/org/apache/ratis/util/TestTimeoutScheduler.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/test/java/org/apache/ratis/util/TestTimeoutScheduler.java b/ratis-common/src/test/java/org/apache/ratis/util/TestTimeoutScheduler.java deleted file mode 100644 index 6a63569..0000000 --- a/ratis-common/src/test/java/org/apache/ratis/util/TestTimeoutScheduler.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.util; - -import org.apache.log4j.Level; -import org.junit.Assert; -import org.junit.Test; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; - -public class TestTimeoutScheduler { - { - LogUtils.setLogLevel(TimeoutScheduler.LOG, Level.ALL); - } - - static class ErrorHandler implements Consumer<RuntimeException> { - private final AtomicBoolean hasError = new AtomicBoolean(false); - - @Override - public void accept(RuntimeException e) { - hasError.set(true); - TimeoutScheduler.LOG.error("Failed", e); - } - - void assertNoError() { - Assert.assertFalse(hasError.get()); - } - } - - @Test(timeout = 1000) - public void testSingleTask() throws Exception { - final TimeoutScheduler scheduler = TimeoutScheduler.newInstance(1); - final TimeDuration grace = TimeDuration.valueOf(100, TimeUnit.MILLISECONDS); - scheduler.setGracePeriod(grace); - Assert.assertFalse(scheduler.hasScheduler()); - - final ErrorHandler errorHandler = new ErrorHandler(); - - final AtomicBoolean fired = new AtomicBoolean(false); - scheduler.onTimeout(TimeDuration.valueOf(250, TimeUnit.MILLISECONDS), () -> { - Assert.assertFalse(fired.get()); - fired.set(true); - }, errorHandler); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertFalse(fired.get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertFalse(fired.get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired.get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired.get()); - Assert.assertFalse(scheduler.hasScheduler()); - - errorHandler.assertNoError(); - } - - @Test(timeout = 1000) - public void testMultipleTasks() throws Exception { - final TimeoutScheduler scheduler = TimeoutScheduler.newInstance(1); - final TimeDuration grace = TimeDuration.valueOf(100, TimeUnit.MILLISECONDS); - scheduler.setGracePeriod(grace); - Assert.assertFalse(scheduler.hasScheduler()); - - final ErrorHandler errorHandler = new ErrorHandler(); - - final AtomicBoolean[] fired = new AtomicBoolean[3]; - for(int i = 0; i < fired.length; i++) { - final AtomicBoolean f = fired[i] = new AtomicBoolean(false); - scheduler.onTimeout(TimeDuration.valueOf(100*i + 50, TimeUnit.MILLISECONDS), () -> { - Assert.assertFalse(f.get()); - f.set(true); - }, errorHandler); - Assert.assertTrue(scheduler.hasScheduler()); - } - - Thread.sleep(100); - Assert.assertTrue(fired[0].get()); - Assert.assertFalse(fired[1].get()); - Assert.assertFalse(fired[2].get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired[0].get()); - Assert.assertTrue(fired[1].get()); - Assert.assertFalse(fired[2].get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired[0].get()); - Assert.assertTrue(fired[1].get()); - Assert.assertTrue(fired[2].get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired[0].get()); - Assert.assertTrue(fired[1].get()); - Assert.assertTrue(fired[2].get()); - Assert.assertFalse(scheduler.hasScheduler()); - - errorHandler.assertNoError(); - } - - @Test(timeout = 1000) - public void testExtendingGracePeriod() throws Exception { - final TimeoutScheduler scheduler = TimeoutScheduler.newInstance(1); - final TimeDuration grace = TimeDuration.valueOf(100, TimeUnit.MILLISECONDS); - scheduler.setGracePeriod(grace); - Assert.assertFalse(scheduler.hasScheduler()); - - final ErrorHandler errorHandler = new ErrorHandler(); - - { - final AtomicBoolean fired = new AtomicBoolean(false); - scheduler.onTimeout(TimeDuration.valueOf(150, TimeUnit.MILLISECONDS), () -> { - Assert.assertFalse(fired.get()); - fired.set(true); - }, errorHandler); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertFalse(fired.get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired.get()); - Assert.assertTrue(scheduler.hasScheduler()); - } - - { - // submit another task during grace period - final AtomicBoolean fired2 = new AtomicBoolean(false); - scheduler.onTimeout(TimeDuration.valueOf(150, TimeUnit.MILLISECONDS), () -> { - Assert.assertFalse(fired2.get()); - fired2.set(true); - }, errorHandler); - - Thread.sleep(100); - Assert.assertFalse(fired2.get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired2.get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired2.get()); - Assert.assertFalse(scheduler.hasScheduler()); - } - - errorHandler.assertNoError(); - } - - @Test(timeout = 1000) - public void testRestartingScheduler() throws Exception { - final TimeoutScheduler scheduler = TimeoutScheduler.newInstance(1); - final TimeDuration grace = TimeDuration.valueOf(100, TimeUnit.MILLISECONDS); - scheduler.setGracePeriod(grace); - Assert.assertFalse(scheduler.hasScheduler()); - - final ErrorHandler errorHandler = new ErrorHandler(); - - for(int i = 0; i < 2; i++) { - final AtomicBoolean fired = new AtomicBoolean(false); - scheduler.onTimeout(TimeDuration.valueOf(150, TimeUnit.MILLISECONDS), () -> { - Assert.assertFalse(fired.get()); - fired.set(true); - }, errorHandler); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertFalse(fired.get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired.get()); - Assert.assertTrue(scheduler.hasScheduler()); - - Thread.sleep(100); - Assert.assertTrue(fired.get()); - Assert.assertFalse(scheduler.hasScheduler()); - } - - errorHandler.assertNoError(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-common/src/test/java/org/apache/ratis/util/TestTraditionalBinaryPrefix.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/test/java/org/apache/ratis/util/TestTraditionalBinaryPrefix.java b/ratis-common/src/test/java/org/apache/ratis/util/TestTraditionalBinaryPrefix.java deleted file mode 100644 index 26a62da..0000000 --- a/ratis-common/src/test/java/org/apache/ratis/util/TestTraditionalBinaryPrefix.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.util; - -import org.junit.Test; - -import static org.apache.ratis.util.TraditionalBinaryPrefix.long2String; -import static org.apache.ratis.util.TraditionalBinaryPrefix.string2long; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -public class TestTraditionalBinaryPrefix { - @Test(timeout = 1000) - public void testTraditionalBinaryPrefix() throws Exception { - //test string2long(..) - String[] symbol = {"k", "m", "g", "t", "p", "e"}; - long m = 1024; - for(String s : symbol) { - assertEquals(0, string2long(0 + s)); - assertEquals(m, string2long(1 + s)); - m *= 1024; - } - - assertEquals(0L, string2long("0")); - assertEquals(1024L, string2long("1k")); - assertEquals(-1024L, string2long("-1k")); - assertEquals(1259520L, string2long("1230K")); - assertEquals(-1259520L, string2long("-1230K")); - assertEquals(104857600L, string2long("100m")); - assertEquals(-104857600L, string2long("-100M")); - assertEquals(956703965184L, string2long("891g")); - assertEquals(-956703965184L, string2long("-891G")); - assertEquals(501377302265856L, string2long("456t")); - assertEquals(-501377302265856L, string2long("-456T")); - assertEquals(11258999068426240L, string2long("10p")); - assertEquals(-11258999068426240L, string2long("-10P")); - assertEquals(1152921504606846976L, string2long("1e")); - assertEquals(-1152921504606846976L, string2long("-1E")); - - String tooLargeNumStr = "10e"; - try { - string2long(tooLargeNumStr); - fail("Test passed for a number " + tooLargeNumStr + " too large"); - } catch (IllegalArgumentException e) { - assertEquals(tooLargeNumStr + " does not fit in a Long", e.getMessage()); - } - - String tooSmallNumStr = "-10e"; - try { - string2long(tooSmallNumStr); - fail("Test passed for a number " + tooSmallNumStr + " too small"); - } catch (IllegalArgumentException e) { - assertEquals(tooSmallNumStr + " does not fit in a Long", e.getMessage()); - } - - String invalidFormatNumStr = "10kb"; - char invalidPrefix = 'b'; - try { - string2long(invalidFormatNumStr); - fail("Test passed for a number " + invalidFormatNumStr - + " has invalid format"); - } catch (IllegalArgumentException e) { - assertEquals("Invalid size prefix '" + invalidPrefix + "' in '" - + invalidFormatNumStr - + "'. Allowed prefixes are k, m, g, t, p, e (case insensitive)", - e.getMessage()); - } - - //test long2string(..) - assertEquals("0", long2String(0, null, 2)); - for(int decimalPlace = 0; decimalPlace < 2; decimalPlace++) { - for(int n = 1; n < TraditionalBinaryPrefix.KILO.getValue(); n++) { - assertEquals(n + "", long2String(n, null, decimalPlace)); - assertEquals(-n + "", long2String(-n, null, decimalPlace)); - } - assertEquals("1 K", long2String(1L << 10, null, decimalPlace)); - assertEquals("-1 K", long2String(-1L << 10, null, decimalPlace)); - } - - assertEquals("8.00 E", long2String(Long.MAX_VALUE, null, 2)); - assertEquals("8.00 E", long2String(Long.MAX_VALUE - 1, null, 2)); - assertEquals("-8 E", long2String(Long.MIN_VALUE, null, 2)); - assertEquals("-8.00 E", long2String(Long.MIN_VALUE + 1, null, 2)); - - final String[] zeros = {" ", ".0 ", ".00 "}; - for(int decimalPlace = 0; decimalPlace < zeros.length; decimalPlace++) { - final String trailingZeros = zeros[decimalPlace]; - - for(int e = 11; e < Long.SIZE - 1; e++) { - final TraditionalBinaryPrefix p - = TraditionalBinaryPrefix.values()[e/10 - 1]; - - { // n = 2^e - final long n = 1L << e; - final String expected = (n/p.getValue()) + " " + p.getSymbol(); - assertEquals("n=" + n, expected, long2String(n, null, 2)); - } - - { // n = 2^e + 1 - final long n = (1L << e) + 1; - final String expected = (n/p.getValue()) + trailingZeros + p.getSymbol(); - assertEquals("n=" + n, expected, long2String(n, null, decimalPlace)); - } - - { // n = 2^e - 1 - final long n = (1L << e) - 1; - final String expected = ((n+1)/p.getValue()) + trailingZeros + p.getSymbol(); - assertEquals("n=" + n, expected, long2String(n, null, decimalPlace)); - } - } - } - - assertEquals("1.50 K", long2String(3L << 9, null, 2)); - assertEquals("1.5 K", long2String(3L << 9, null, 1)); - assertEquals("1.50 M", long2String(3L << 19, null, 2)); - assertEquals("2 M", long2String(3L << 19, null, 0)); - assertEquals("3 G", long2String(3L << 30, null, 2)); - - assertEquals("0 B", byteDescription(0)); - assertEquals("-100 B", byteDescription(-100)); - assertEquals("1 KB", byteDescription(1024)); - assertEquals("1.50 KB", byteDescription(3L << 9)); - assertEquals("1.50 MB", byteDescription(3L << 19)); - assertEquals("3 GB", byteDescription(3L << 30)); - } - - private static String byteDescription(long len) { - return long2String(len, "B", 2); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-examples/pom.xml ---------------------------------------------------------------------- diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml index e56a2dd..cf37b6b 100644 --- a/ratis-examples/pom.xml +++ b/ratis-examples/pom.xml @@ -48,22 +48,12 @@ <artifactId>ratis-client</artifactId> <groupId>org.apache.ratis</groupId> </dependency> - <dependency> - <artifactId>ratis-client</artifactId> - <groupId>org.apache.ratis</groupId> - <scope>test</scope> - <type>test-jar</type> - </dependency> <dependency> <artifactId>ratis-server</artifactId> <groupId>org.apache.ratis</groupId> </dependency> <dependency> - <groupId>com.beust</groupId> - <artifactId>jcommander</artifactId> - </dependency> - <dependency> <artifactId>ratis-server</artifactId> <groupId>org.apache.ratis</groupId> <scope>test</scope> @@ -110,6 +100,11 @@ </dependency> <dependency> + <groupId>com.beust</groupId> + <artifactId>jcommander</artifactId> + </dependency> + + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/pom.xml ---------------------------------------------------------------------- diff --git a/ratis-grpc/pom.xml b/ratis-grpc/pom.xml index 4a3ab81..bd46c69 100644 --- a/ratis-grpc/pom.xml +++ b/ratis-grpc/pom.xml @@ -71,16 +71,5 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <scope>test</scope> - </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestGroupManagementWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestGroupManagementWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestGroupManagementWithGrpc.java deleted file mode 100644 index 657bfd1..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestGroupManagementWithGrpc.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.MiniRaftCluster; -import org.apache.ratis.server.impl.GroupManagementBaseTest; - -public class TestGroupManagementWithGrpc extends GroupManagementBaseTest { - @Override - public MiniRaftCluster.Factory<? extends MiniRaftCluster> getClusterFactory() { - return MiniRaftClusterWithGrpc.FACTORY; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestLeaderElectionWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestLeaderElectionWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestLeaderElectionWithGrpc.java deleted file mode 100644 index eb08336..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestLeaderElectionWithGrpc.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.server.impl.BlockRequestHandlingInjection; -import org.apache.ratis.server.impl.LeaderElectionTests; -import org.junit.Test; - -public class TestLeaderElectionWithGrpc - extends LeaderElectionTests<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet { - - @Override - @Test - public void testEnforceLeader() throws Exception { - super.testEnforceLeader(); - - MiniRaftClusterWithGrpc.sendServerRequestInjection.clear(); - BlockRequestHandlingInjection.getInstance().unblockAll(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftAsyncWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftAsyncWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftAsyncWithGrpc.java deleted file mode 100644 index 614787e..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftAsyncWithGrpc.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.RaftAsyncTests; - -public class TestRaftAsyncWithGrpc extends RaftAsyncTests<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet { -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftExceptionWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftExceptionWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftExceptionWithGrpc.java deleted file mode 100644 index d2b71bc..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftExceptionWithGrpc.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.RaftExceptionBaseTest; - -public class TestRaftExceptionWithGrpc - extends RaftExceptionBaseTest<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet { -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftReconfigurationWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftReconfigurationWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftReconfigurationWithGrpc.java deleted file mode 100644 index 29f8bea..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftReconfigurationWithGrpc.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.log4j.Level; -import org.apache.ratis.grpc.server.GrpcServerProtocolService; -import org.apache.ratis.server.impl.RaftReconfigurationBaseTest; -import org.apache.ratis.util.LogUtils; - -import java.io.IOException; - -public class TestRaftReconfigurationWithGrpc extends RaftReconfigurationBaseTest { - static { - LogUtils.setLogLevel(GrpcServerProtocolService.LOG, Level.DEBUG); - } - - @Override - public MiniRaftClusterWithGrpc getCluster(int peerNum) { - return MiniRaftClusterWithGrpc.FACTORY.newCluster(peerNum, prop); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java deleted file mode 100644 index 2ec7ae8..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.BaseTest; -import org.apache.ratis.RaftTestUtil; -import org.apache.ratis.conf.RaftProperties; -import org.apache.ratis.protocol.RaftPeerId; -import org.apache.ratis.server.impl.ServerImplUtils; -import org.apache.ratis.statemachine.StateMachine; -import org.junit.Test; - -import java.io.IOException; -import java.nio.channels.OverlappingFileLockException; - -public class TestRaftServerWithGrpc extends BaseTest { - - @Test - public void testServerRestartOnException() throws Exception { - RaftProperties properties = new RaftProperties(); - final MiniRaftClusterWithGrpc cluster - = MiniRaftClusterWithGrpc.FACTORY.newCluster(1, properties); - cluster.start(); - RaftPeerId leaderId = RaftTestUtil.waitForLeader(cluster).getId(); - GrpcConfigKeys.Server.setPort(properties, cluster.getLeader().getServerRpc().getInetSocketAddress().getPort()); - // Create a raft server proxy with server rpc bound to a different address - // compared to leader. This helps in locking the raft storage directory to - // be used by next raft server proxy instance. - final StateMachine stateMachine = cluster.getLeader().getStateMachine(); - ServerImplUtils.newRaftServer(leaderId, cluster.getGroup(), gid -> stateMachine, properties, null); - // Close the server rpc for leader so that new raft server can be bound to it. - cluster.getLeader().getServerRpc().close(); - - // Create a raft server proxy with server rpc bound to same address as - // the leader. This step would fail as the raft storage has been locked by - // the raft server proxy created earlier. Raft server proxy should close - // the rpc server on failure. - testFailureCase("start a new server with the same address", - () -> ServerImplUtils.newRaftServer(leaderId, cluster.getGroup(), gid -> stateMachine, properties, null).start(), - IOException.class, OverlappingFileLockException.class); - // Try to start a raft server rpc at the leader address. - cluster.getServer(leaderId).getFactory().newRaftServerRpc(cluster.getServer(leaderId)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftSnapshotWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftSnapshotWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftSnapshotWithGrpc.java deleted file mode 100644 index a960478..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftSnapshotWithGrpc.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.MiniRaftCluster; -import org.apache.ratis.statemachine.RaftSnapshotBaseTest; - -public class TestRaftSnapshotWithGrpc extends RaftSnapshotBaseTest { - @Override - public MiniRaftCluster.Factory<?> getFactory() { - return MiniRaftClusterWithGrpc.FACTORY; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftStateMachineExceptionWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftStateMachineExceptionWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftStateMachineExceptionWithGrpc.java deleted file mode 100644 index c8789a7..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftStateMachineExceptionWithGrpc.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.server.impl.RaftStateMachineExceptionTests; - -public class TestRaftStateMachineExceptionWithGrpc - extends RaftStateMachineExceptionTests<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet { - -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftStream.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftStream.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftStream.java deleted file mode 100644 index ba31b2b..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftStream.java +++ /dev/null @@ -1,311 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.log4j.Level; -import org.apache.ratis.BaseTest; -import org.apache.ratis.RaftTestUtil; -import org.apache.ratis.conf.RaftProperties; -import org.apache.ratis.grpc.client.GrpcClientStreamer; -import org.apache.ratis.grpc.client.GrpcOutputStream; -import org.apache.ratis.protocol.ClientId; -import org.apache.ratis.server.impl.RaftServerImpl; -import org.apache.ratis.server.protocol.TermIndex; -import org.apache.ratis.server.storage.RaftLog; -import org.apache.ratis.proto.RaftProtos; -import org.apache.ratis.util.LogUtils; -import org.apache.ratis.util.SizeInBytes; -import org.apache.ratis.util.StringUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.IOException; -import java.util.*; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Supplier; - -import static org.apache.ratis.RaftTestUtil.waitForLeader; -import static org.junit.Assert.fail; - -@Ignore -public class TestRaftStream extends BaseTest { - static { - LogUtils.setLogLevel(GrpcClientStreamer.LOG, Level.ALL); - } - - private static final RaftProperties prop = new RaftProperties(); - private static final int NUM_SERVERS = 3; - private static final byte[] BYTES = new byte[4]; - - private MiniRaftClusterWithGrpc cluster; - - @After - public void tearDown() { - if (cluster != null) { - cluster.shutdown(); - } - } - - private byte[] toBytes(int i) { - return toBytes(i, BYTES); - } - private byte[] toBytes(int i, byte[] b) { - b[0] = (byte) ((i >>> 24) & 0xFF); - b[1] = (byte) ((i >>> 16) & 0xFF); - b[2] = (byte) ((i >>> 8) & 0xFF); - b[3] = (byte) (i & 0xFF); - return b; - } - - @Test - public void testSimpleWrite() throws Exception { - final int numRequests = 500; - LOG.info("Running testSimpleWrite, numRequests=" + numRequests); - - // default 64K is too large for a test - GrpcConfigKeys.OutputStream.setBufferSize(prop, SizeInBytes.valueOf(4)); - cluster = MiniRaftClusterWithGrpc.FACTORY.newCluster(NUM_SERVERS, prop); - - cluster.start(); - RaftServerImpl leader = waitForLeader(cluster); - - try (GrpcOutputStream out = new GrpcOutputStream(prop, ClientId.randomId(), - cluster.getGroup(), leader.getId())) { - for (int i = 0; i < numRequests; i++) { // generate requests - out.write(toBytes(i)); - } - } - - // check the leader's raft log - final RaftLog raftLog = leader.getState().getLog(); - final AtomicInteger i = new AtomicInteger(); - checkLog(raftLog, numRequests, () -> toBytes(i.getAndIncrement())); - } - - private void checkLog(RaftLog raftLog, long expectedCommittedIndex, - Supplier<byte[]> s) throws IOException { - long committedIndex = raftLog.getLastCommittedIndex(); - Assert.assertEquals(expectedCommittedIndex, committedIndex); - // check the log content - TermIndex[] entries = raftLog.getEntries(1, expectedCommittedIndex + 1); - for (TermIndex entry : entries) { - RaftProtos.LogEntryProto log = raftLog.get(entry.getIndex()); - byte[] logData = log.getStateMachineLogEntry().getLogData().toByteArray(); - byte[] expected = s.get(); - LOG.info("log " + entry + " " + log.getLogEntryBodyCase() + " " + StringUtils.bytes2HexString(logData)); - Assert.assertEquals(expected.length, logData.length); - Assert.assertArrayEquals(expected, logData); - } - } - - @Test - public void testWriteAndFlush() throws Exception { - LOG.info("Running testWriteAndFlush"); - - GrpcConfigKeys.OutputStream.setBufferSize(prop, SizeInBytes.valueOf(ByteValue.BUFFERSIZE)); - cluster = MiniRaftClusterWithGrpc.FACTORY.newCluster(NUM_SERVERS, prop); - cluster.start(); - - RaftServerImpl leader = waitForLeader(cluster); - GrpcOutputStream out = new GrpcOutputStream(prop, ClientId.randomId(), - cluster.getGroup(), leader.getId()); - - int[] lengths = new int[]{1, 500, 1023, 1024, 1025, 2048, 3000, 3072}; - ByteValue[] values = new ByteValue[lengths.length]; - for (int i = 0; i < values.length; i++) { - values[i] = new ByteValue(lengths[i], (byte) 9); - } - - List<byte[]> expectedTxs = new ArrayList<>(); - for (ByteValue v : values) { - byte[] data = v.genData(); - expectedTxs.addAll(v.getTransactions()); - out.write(data); - out.flush(); - - // make sure after the flush the data has been committed - Assert.assertEquals(expectedTxs.size(), - leader.getState().getLastAppliedIndex()); - } - out.close(); - - try { - out.write(0); - fail("The OutputStream has been closed"); - } catch (IOException ignored) { - } - - LOG.info("Start to check leader's log"); - final AtomicInteger index = new AtomicInteger(0); - checkLog(leader.getState().getLog(), expectedTxs.size(), - () -> expectedTxs.get(index.getAndIncrement())); - } - - private static class ByteValue { - final static int BUFFERSIZE = 1024; - - final int length; - final byte value; - final int numTx; - byte[] data; - - ByteValue(int length, byte value) { - this.length = length; - this.value = value; - numTx = (length - 1) / BUFFERSIZE + 1; - } - - byte[] genData() { - data = new byte[length]; - Arrays.fill(data, value); - return data; - } - - Collection<byte[]> getTransactions() { - if (data.length <= BUFFERSIZE) { - return Collections.singletonList(data); - } else { - List<byte[]> list = new ArrayList<>(); - for (int i = 0; i < numTx; i++) { - int txSize = Math.min(BUFFERSIZE, length - BUFFERSIZE * i); - byte[] t = new byte[txSize]; - Arrays.fill(t, value); - list.add(t); - } - return list; - } - } - } - - @Test - public void testWriteWithOffset() throws Exception { - LOG.info("Running testWriteWithOffset"); - GrpcConfigKeys.OutputStream.setBufferSize(prop, SizeInBytes.valueOf(ByteValue.BUFFERSIZE)); - - cluster = MiniRaftClusterWithGrpc.FACTORY.newCluster(NUM_SERVERS, prop); - cluster.start(); - RaftServerImpl leader = waitForLeader(cluster); - - GrpcOutputStream out = new GrpcOutputStream(prop, ClientId.randomId(), - cluster.getGroup(), leader.getId()); - - byte[] b1 = new byte[ByteValue.BUFFERSIZE / 2]; - Arrays.fill(b1, (byte) 1); - byte[] b2 = new byte[ByteValue.BUFFERSIZE]; - Arrays.fill(b2, (byte) 2); - byte[] b3 = new byte[ByteValue.BUFFERSIZE * 2 + ByteValue.BUFFERSIZE / 2]; - Arrays.fill(b3, (byte) 3); - byte[] b4 = new byte[ByteValue.BUFFERSIZE * 4]; - Arrays.fill(b3, (byte) 4); - - byte[] expected = new byte[ByteValue.BUFFERSIZE * 8]; - byte[][] data = new byte[][]{b1, b2, b3, b4}; - final Random random = new Random(); - int totalSize = 0; - for (byte[] b : data) { - System.arraycopy(b, 0, expected, totalSize, b.length); - totalSize += b.length; - - int written = 0; - while (written < b.length) { - int toWrite = random.nextInt(b.length - written) + 1; - LOG.info("write {} bytes", toWrite); - out.write(b, written, toWrite); - written += toWrite; - } - } - out.close(); - - final RaftLog log = leader.getState().getLog(); - // 0.5 + 1 + 2.5 + 4 = 8 - Assert.assertEquals(8, leader.getState().getLastAppliedIndex()); - Assert.assertEquals(8, log.getLastCommittedIndex()); - TermIndex[] entries = log.getEntries(1, 9); - byte[] actual = new byte[ByteValue.BUFFERSIZE * 8]; - totalSize = 0; - for (TermIndex e : entries) { - byte[] eValue = log.get(e.getIndex()).getStateMachineLogEntry().getLogData().toByteArray(); - Assert.assertEquals(ByteValue.BUFFERSIZE, eValue.length); - System.arraycopy(eValue, 0, actual, totalSize, eValue.length); - totalSize += eValue.length; - } - Assert.assertArrayEquals(expected, actual); - } - - /** - * Write while leader is killed - */ - @Test - public void testKillLeader() throws Exception { - LOG.info("Running testChangeLeader"); - - GrpcConfigKeys.OutputStream.setBufferSize(prop, SizeInBytes.valueOf(4)); - cluster = MiniRaftClusterWithGrpc.FACTORY.newCluster(NUM_SERVERS, prop); - cluster.start(); - final RaftServerImpl leader = waitForLeader(cluster); - - final AtomicBoolean running = new AtomicBoolean(true); - final AtomicReference<Boolean> success = new AtomicReference<>(); - final AtomicInteger result = new AtomicInteger(0); - final CountDownLatch latch = new CountDownLatch(1); - - new Thread(() -> { - LOG.info("Writer thread starts"); - int count = 0; - try (GrpcOutputStream out = new GrpcOutputStream(prop, ClientId.randomId(), - cluster.getGroup(), leader.getId())) { - while (running.get()) { - out.write(toBytes(count++)); - Thread.sleep(10); - } - success.set(true); - result.set(count); - } catch (Exception e) { - LOG.info("Got exception when writing", e); - success.set(false); - } finally { - latch.countDown(); - } - }).start(); - - // force change the leader - Thread.sleep(500); - RaftTestUtil.waitAndKillLeader(cluster); - final RaftServerImpl newLeader = waitForLeader(cluster); - Assert.assertNotEquals(leader.getId(), newLeader.getId()); - Thread.sleep(500); - - running.set(false); - latch.await(5, TimeUnit.SECONDS); - LOG.info("Writer success? " + success.get()); - Assert.assertTrue(success.get()); - // total number of tx should be >= result + 2, where 2 means two NoOp from - // leaders. It may be larger than result+2 because the client may resend - // requests and we do not have retry cache on servers yet. - LOG.info("last applied index: {}. total number of requests: {}", - newLeader.getState().getLastAppliedIndex(), result.get()); - Assert.assertTrue( - newLeader.getState().getLastAppliedIndex() >= result.get() + 1); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftWithGrpc.java deleted file mode 100644 index d98be53..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRaftWithGrpc.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.MiniRaftCluster; -import org.apache.ratis.RaftBasicTests; -import org.apache.ratis.RaftTestUtil; -import org.apache.ratis.client.RaftClient; -import org.apache.ratis.protocol.RaftClientReply; -import org.apache.ratis.server.impl.BlockRequestHandlingInjection; -import org.apache.ratis.server.impl.RaftServerTestUtil; -import org.apache.ratis.server.protocol.TermIndex; -import org.apache.ratis.statemachine.SimpleStateMachine4Testing; -import org.apache.ratis.statemachine.StateMachine; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; -import java.util.concurrent.CompletableFuture; - -import static org.apache.ratis.RaftTestUtil.waitForLeader; - -public class TestRaftWithGrpc - extends RaftBasicTests<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet { - - { - getProperties().setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, - SimpleStateMachine4Testing.class, StateMachine.class); - } - - @Override - @Test - public void testWithLoad() throws Exception { - super.testWithLoad(); - BlockRequestHandlingInjection.getInstance().unblockAll(); - } - - @Test - public void testRequestTimeout() throws Exception { - try(MiniRaftClusterWithGrpc cluster = newCluster(NUM_SERVERS)) { - cluster.start(); - testRequestTimeout(false, cluster, LOG); - } - } - - @Test - public void testUpdateViaHeartbeat() throws Exception { - LOG.info("Running testUpdateViaHeartbeat"); - final MiniRaftClusterWithGrpc cluster = newCluster(NUM_SERVERS); - cluster.start(); - waitForLeader(cluster); - long waitTime = 5000; - try (final RaftClient client = cluster.createClient()) { - // block append requests - cluster.getServerAliveStream() - .filter(impl -> !impl.isLeader()) - .map(SimpleStateMachine4Testing::get) - .forEach(SimpleStateMachine4Testing::blockWriteStateMachineData); - - CompletableFuture<RaftClientReply> - replyFuture = client.sendAsync(new RaftTestUtil.SimpleMessage("abc")); - Thread.sleep(waitTime); - // replyFuture should not be completed until append request is unblocked. - Assert.assertTrue(!replyFuture.isDone()); - // unblock append request. - cluster.getServerAliveStream() - .filter(impl -> !impl.isLeader()) - .map(SimpleStateMachine4Testing::get) - .forEach(SimpleStateMachine4Testing::unblockWriteStateMachineData); - - long index = cluster.getLeader().getState().getLog().getNextIndex(); - TermIndex[] leaderEntries = cluster.getLeader().getState().getLog().getEntries(0, Integer.MAX_VALUE); - // The entries have been appended in the followers - // although the append entry timed out at the leader - cluster.getServerAliveStream().forEach(raftServer -> { - Assert.assertEquals(raftServer.getState().getLog().getNextIndex(), index); - if (!raftServer.isLeader()) { - TermIndex[] serverEntries = raftServer.getState().getLog().getEntries(0, Integer.MAX_VALUE); - Assert.assertArrayEquals(serverEntries, leaderEntries); - } - }); - - // Wait for heartbeats from leader to be received by followers - Thread.sleep(500); - RaftServerTestUtil.getLogAppenders(cluster.getLeader()).forEach(logAppender -> { - // FollowerInfo in the leader state should have updated next and match index. - final long followerMatchIndex = logAppender.getFollower().getMatchIndex(); - Assert.assertTrue(followerMatchIndex >= index - 1); - Assert.assertEquals(followerMatchIndex + 1, logAppender.getFollower().getNextIndex()); - }); - } - cluster.shutdown(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRetryCacheWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRetryCacheWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRetryCacheWithGrpc.java deleted file mode 100644 index cd04b43..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestRetryCacheWithGrpc.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.apache.log4j.Level; -import org.apache.ratis.MiniRaftCluster; -import org.apache.ratis.RaftTestUtil; -import org.apache.ratis.RetryCacheTests; -import org.apache.ratis.client.RaftClient; -import org.apache.ratis.client.RaftClientRpc; -import org.apache.ratis.protocol.ClientId; -import org.apache.ratis.protocol.RaftClientRequest; -import org.apache.ratis.protocol.RaftPeerId; -import org.apache.ratis.server.impl.RaftServerImpl; -import org.apache.ratis.proto.RaftProtos; -import org.apache.ratis.util.LogUtils; -import org.junit.Assert; -import org.junit.Test; - -public class TestRetryCacheWithGrpc extends RetryCacheTests { - static { - LogUtils.setLogLevel(RaftServerImpl.LOG, Level.DEBUG); - } - - private final MiniRaftClusterWithGrpc cluster; - - public TestRetryCacheWithGrpc() throws IOException { - cluster = MiniRaftClusterWithGrpc.FACTORY.newCluster( - NUM_SERVERS, properties); - Assert.assertNull(cluster.getLeader()); - } - - @Override - public MiniRaftClusterWithGrpc getCluster() { - return cluster; - } - - @Test - public void testAsyncRetryWithReplicatedAll() throws Exception { - final MiniRaftCluster cluster = getCluster(); - RaftTestUtil.waitForLeader(cluster); - - final RaftPeerId leaderId = cluster.getLeaderAndSendFirstMessage().getId(); - long oldLastApplied = cluster.getLeader().getState().getLastAppliedIndex(); - - // Kill a follower - final RaftPeerId killedFollower = cluster.getFollowers().get(0).getId(); - cluster.killServer(killedFollower); - - final long callId = 999; - final long seqNum = 111; - final ClientId clientId = ClientId.randomId(); - - // Retry with the same clientId and callId - final List<CompletableFuture<RaftClient>> futures = new ArrayList<>(); - futures.addAll(sendRetry(clientId, leaderId, callId, seqNum, cluster)); - futures.addAll(sendRetry(clientId, leaderId, callId, seqNum, cluster)); - - // restart the killed follower - cluster.restartServer(killedFollower, false); - for(CompletableFuture<RaftClient> f : futures) { - f.join().close(); - } - assertServer(cluster, clientId, callId, oldLastApplied); - } - - List<CompletableFuture<RaftClient>> sendRetry( - ClientId clientId, RaftPeerId leaderId, long callId, long seqNum, MiniRaftCluster cluster) - throws Exception { - List<CompletableFuture<RaftClient>> futures = new ArrayList<>(); - final int numRequest = 3; - for (int i = 0; i < numRequest; i++) { - final RaftClient client = cluster.createClient(leaderId, cluster.getGroup(), clientId); - final RaftClientRpc rpc = client.getClientRpc(); - final RaftClientRequest request = cluster.newRaftClientRequest(client.getId(), leaderId, - callId, seqNum, new RaftTestUtil.SimpleMessage("message"), RaftProtos.ReplicationLevel.ALL); - - LOG.info("{} sendRequestAsync {}", i, request); - futures.add(rpc.sendRequestAsync(request) - .thenApply(reply -> assertReply(reply, client, callId))); - } - - for(CompletableFuture<RaftClient> f : futures) { - try { - f.get(200, TimeUnit.MILLISECONDS); - Assert.fail("It should timeout for ReplicationLevel.ALL since a follower is down"); - } catch(TimeoutException te) { - LOG.info("Expected " + te); - } - } - return futures; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestServerInformationWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestServerInformationWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestServerInformationWithGrpc.java deleted file mode 100644 index 30be724..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestServerInformationWithGrpc.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.server.impl.ServerInformationBaseTest; - -public class TestServerInformationWithGrpc - extends ServerInformationBaseTest<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet { -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestServerRestartWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestServerRestartWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestServerRestartWithGrpc.java deleted file mode 100644 index 682b3ba..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestServerRestartWithGrpc.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.server.ServerRestartTests; - -public class TestServerRestartWithGrpc - extends ServerRestartTests<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet { -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestStateMachineShutdownWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestStateMachineShutdownWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestStateMachineShutdownWithGrpc.java deleted file mode 100644 index d8d1d0d..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestStateMachineShutdownWithGrpc.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.server.impl.StateMachineShutdownTests; - -public class TestStateMachineShutdownWithGrpc - extends StateMachineShutdownTests<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet{ - -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestWatchRequestWithGrpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestWatchRequestWithGrpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestWatchRequestWithGrpc.java deleted file mode 100644 index 7b9061b..0000000 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/TestWatchRequestWithGrpc.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.grpc; - -import org.apache.ratis.WatchRequestTests; - -public class TestWatchRequestWithGrpc - extends WatchRequestTests<MiniRaftClusterWithGrpc> - implements MiniRaftClusterWithGrpc.FactoryGet { -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-grpc/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/resources/log4j.properties b/ratis-grpc/src/test/resources/log4j.properties deleted file mode 100644 index ced0687..0000000 --- a/ratis-grpc/src/test/resources/log4j.properties +++ /dev/null @@ -1,18 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# log4j configuration used during build and unit tests - -log4j.rootLogger=info,stdout -log4j.threshold=ALL -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-netty/pom.xml ---------------------------------------------------------------------- diff --git a/ratis-netty/pom.xml b/ratis-netty/pom.xml index b573420..42d8656 100644 --- a/ratis-netty/pom.xml +++ b/ratis-netty/pom.xml @@ -72,16 +72,5 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <scope>test</scope> - </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-netty/src/test/java/org/apache/ratis/netty/TestGroupManagementWithNetty.java ---------------------------------------------------------------------- diff --git a/ratis-netty/src/test/java/org/apache/ratis/netty/TestGroupManagementWithNetty.java b/ratis-netty/src/test/java/org/apache/ratis/netty/TestGroupManagementWithNetty.java deleted file mode 100644 index e049e32..0000000 --- a/ratis-netty/src/test/java/org/apache/ratis/netty/TestGroupManagementWithNetty.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.netty; - -import org.apache.ratis.MiniRaftCluster; -import org.apache.ratis.server.impl.GroupManagementBaseTest; - -public class TestGroupManagementWithNetty extends GroupManagementBaseTest { - @Override - public MiniRaftCluster.Factory<? extends MiniRaftCluster> getClusterFactory() { - return MiniRaftClusterWithNetty.FACTORY; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-netty/src/test/java/org/apache/ratis/netty/TestLeaderElectionWithNetty.java ---------------------------------------------------------------------- diff --git a/ratis-netty/src/test/java/org/apache/ratis/netty/TestLeaderElectionWithNetty.java b/ratis-netty/src/test/java/org/apache/ratis/netty/TestLeaderElectionWithNetty.java deleted file mode 100644 index 6d40b60..0000000 --- a/ratis-netty/src/test/java/org/apache/ratis/netty/TestLeaderElectionWithNetty.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.netty; - -import org.apache.ratis.server.impl.BlockRequestHandlingInjection; -import org.apache.ratis.server.impl.LeaderElectionTests; -import org.junit.Test; - -public class TestLeaderElectionWithNetty - extends LeaderElectionTests<MiniRaftClusterWithNetty> - implements MiniRaftClusterWithNetty.FactoryGet { - @Override - @Test - public void testEnforceLeader() throws Exception { - super.testEnforceLeader(); - - MiniRaftClusterWithNetty.sendServerRequest.clear(); - BlockRequestHandlingInjection.getInstance().unblockAll(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-netty/src/test/java/org/apache/ratis/netty/TestRaftExceptionWithNetty.java ---------------------------------------------------------------------- diff --git a/ratis-netty/src/test/java/org/apache/ratis/netty/TestRaftExceptionWithNetty.java b/ratis-netty/src/test/java/org/apache/ratis/netty/TestRaftExceptionWithNetty.java deleted file mode 100644 index 3414a65..0000000 --- a/ratis-netty/src/test/java/org/apache/ratis/netty/TestRaftExceptionWithNetty.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.netty; - -import org.apache.ratis.RaftExceptionBaseTest; - -public class TestRaftExceptionWithNetty - extends RaftExceptionBaseTest<MiniRaftClusterWithNetty> - implements MiniRaftClusterWithNetty.FactoryGet { -} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5c37675f/ratis-netty/src/test/java/org/apache/ratis/netty/TestRaftReconfigurationWithNetty.java ---------------------------------------------------------------------- diff --git a/ratis-netty/src/test/java/org/apache/ratis/netty/TestRaftReconfigurationWithNetty.java b/ratis-netty/src/test/java/org/apache/ratis/netty/TestRaftReconfigurationWithNetty.java deleted file mode 100644 index 15fa8e6..0000000 --- a/ratis-netty/src/test/java/org/apache/ratis/netty/TestRaftReconfigurationWithNetty.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.netty; - -import java.io.IOException; - -import org.apache.ratis.MiniRaftCluster; -import org.apache.ratis.server.impl.RaftReconfigurationBaseTest; - -public class TestRaftReconfigurationWithNetty - extends RaftReconfigurationBaseTest { - @Override - public MiniRaftCluster getCluster(int peerNum) throws IOException { - return MiniRaftClusterWithNetty.FACTORY.newCluster(peerNum, prop); - } -}
