-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 抽取 LearnerSnapshotManager (#46) (#98) * refactor --------- Co-authored-by: 李航 <30505377+githubli97@users.noreply.github.com>
- Loading branch information
1 parent
0b12640
commit d660108
Showing
7 changed files
with
203 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...-facade/src/main/java/com/ofcoder/klein/consensus/facade/exception/SnapshotException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 com.ofcoder.klein.consensus.facade.exception; | ||
|
||
import com.ofcoder.klein.common.exception.KleinException; | ||
|
||
/** | ||
* Snapshot Exception. | ||
* | ||
* @author hang.li | ||
*/ | ||
public class SnapshotException extends KleinException { | ||
public SnapshotException(final String message) { | ||
super(message); | ||
} | ||
|
||
public SnapshotException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...axos/src/test/java/com/ofcoder/klein/consensus/paxos/core/LearnerSnapshotManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.ofcoder.klein.consensus.paxos.core; | ||
|
||
public class LearnerSnapshotManagerTest { | ||
|
||
// private Learner learner; | ||
// private ConsensusProp consensusProp; | ||
// private LearnerSnapshotManager learnerSnapshotManager; | ||
// | ||
// @Before | ||
// public void setUp() { | ||
// learner = mock(Learner.class); | ||
// consensusProp = mock(ConsensusProp.class); | ||
// when(consensusProp.getSnapshotStrategy()).thenReturn("10 5"); // 每10秒5个请求生成一次快照 | ||
// | ||
// LearnerSnapshotManager.initAndStart(consensusProp, learner); | ||
// learnerSnapshotManager = LearnerSnapshotManager.getInstance(); | ||
// } | ||
// | ||
// @Test | ||
// public void testInitAndStart() { | ||
// assertNotNull(learnerSnapshotManager); | ||
// } | ||
// | ||
// @Test | ||
// public void testAddReqCount() { | ||
// learnerSnapshotManager.addReqCount(); | ||
// assertEquals(1, learnerSnapshotManager.getReqCount()); | ||
// } | ||
|
||
// @Test | ||
// public void testGenerateSnap() { | ||
// Map<String, SMApplier> sms = new HashMap<>(); | ||
// SMApplier smApplier = mock(SMApplier.class); | ||
// sms.put("testGroup", smApplier); | ||
// | ||
// when(learner.getSms()).thenReturn(sms); | ||
// | ||
// Map<String, Snap> snaps = learnerSnapshotManager.generateSnap(); | ||
// | ||
// assertNotNull(snaps); | ||
// assertTrue(snaps.containsKey("testGroup")); | ||
// } | ||
// | ||
// @Test | ||
// public void testCheckAndSnapshot() throws InterruptedException { | ||
// Map<String, SMApplier> sms = new HashMap<>(); | ||
// SMApplier smApplier = mock(SMApplier.class); | ||
// sms.put("testGroup", smApplier); | ||
// | ||
// when(learner.getSms()).thenReturn(sms); | ||
// | ||
// learnerSnapshotManager.addReqCount(); | ||
// learnerSnapshotManager.addReqCount(); | ||
// learnerSnapshotManager.addReqCount(); | ||
// learnerSnapshotManager.addReqCount(); | ||
// learnerSnapshotManager.addReqCount(); | ||
// | ||
// TimeUnit.SECONDS.sleep(11); // 等待足够时间以触发快照生成 | ||
// | ||
// Map<String, Snap> snaps = learnerSnapshotManager.generateSnap(); | ||
// | ||
// assertNotNull(snaps); | ||
// assertTrue(snaps.containsKey("testGroup")); | ||
// } | ||
|
||
// @Test | ||
// public void testShutdown() { | ||
// learnerSnapshotManager.shutdown(); | ||
// verify(learner).getSms(); // 验证在关闭时会调用 generateSnap | ||
// } | ||
} |