-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1e001d
commit bdd7024
Showing
5 changed files
with
287 additions
and
18 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
21 changes: 21 additions & 0 deletions
21
ambry-clustermap/src/test/java/com/github/ambry/clustermap/TestReplica.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,21 @@ | ||
package com.github.ambry.clustermap; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
|
||
// Permits Replica to be constructed with a null Partition | ||
public class TestReplica extends Replica { | ||
public TestReplica(HardwareLayout hardwareLayout, JSONObject jsonObject) throws JSONException { | ||
super(hardwareLayout, null, jsonObject); | ||
} | ||
|
||
public TestReplica(TestUtils.TestHardwareLayout hardwareLayout, Disk disk) throws JSONException { | ||
super(null, disk, hardwareLayout.clusterMapConfig); | ||
} | ||
|
||
@Override | ||
public void validatePartition() { | ||
// Null OK | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
ambry-store/src/main/java/com/github/ambry/store/ReplicationProtocolTransitionType.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,73 @@ | ||
package com.github.ambry.store; | ||
|
||
public enum ReplicationProtocolTransitionType { | ||
/** | ||
* Pre restart protocol: NA | ||
* Bootstrap status: NA | ||
* Post restart protocol: Blob based | ||
*/ | ||
NEW_PARTITION_TO_BLOB_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: NA | ||
* Bootstrap status: NA | ||
* Post restart protocol: File based | ||
*/ | ||
NEW_PARTITION_TO_FILE_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: Blob based | ||
* Bootstrap status: Complete | ||
* Post restart protocol: File based | ||
*/ | ||
BLOB_BASED_COMPLETE_TO_FILE_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: File based | ||
* Bootstrap status: Complete | ||
* Post restart protocol: Blob based | ||
*/ | ||
FILE_BASED_COMPLETE_TO_BLOB_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: Blob based | ||
* Bootstrap status: Complete | ||
* Post restart protocol: Blob based | ||
*/ | ||
BLOB_BASED_COMPLETE_TO_BLOB_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: File based | ||
* Bootstrap status: Complete | ||
* Post restart protocol: File based | ||
*/ | ||
FILE_BASED_COMPLETE_TO_FILE_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: Blob based | ||
* Bootstrap status: InComplete | ||
* Post restart protocol: Blob based | ||
*/ | ||
BLOB_BASED_INCOMPLETE_TO_BLOB_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: File based | ||
* Bootstrap status: InComplete | ||
* Post restart protocol: File based | ||
*/ | ||
FILE_BASED_INCOMPLETE_TO_FILE_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: Blob based | ||
* Bootstrap status: InComplete | ||
* Post restart protocol: File based | ||
*/ | ||
BLOB_BASED_INCOMPLETE_TO_FILE_BASED_BOOTSTRAP, | ||
|
||
/** | ||
* Pre restart protocol: File based | ||
* Bootstrap status: InComplete | ||
* Post restart protocol: Blob based | ||
*/ | ||
FILE_BASED_INCOMPLETE_TO_BLOB_BASED_BOOTSTRAP | ||
} |
151 changes: 151 additions & 0 deletions
151
ambry-store/src/test/java/com/github/ambry/store/BootstrapControllerTest.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,151 @@ | ||
/** | ||
* Copyright 2024 LinkedIn Corp. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.github.ambry.store; | ||
|
||
import com.github.ambry.clustermap.ClusterParticipant; | ||
import com.github.ambry.clustermap.PartitionId; | ||
import com.github.ambry.clustermap.PartitionStateChangeListener; | ||
import com.github.ambry.clustermap.TestReplica; | ||
import com.github.ambry.clustermap.ReplicaSyncUpManager; | ||
import com.github.ambry.clustermap.StateModelListenerType; | ||
import com.github.ambry.config.ServerConfig; | ||
import com.github.ambry.config.ServerReplicationMode; | ||
import com.github.ambry.config.StoreConfig; | ||
import com.github.ambry.config.VerifiableProperties; | ||
import com.github.ambry.server.StoreManager; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
|
||
public class BootstrapControllerTest { | ||
private static ServerConfig serverConfig; | ||
private static StoreConfig storeConfig; | ||
private static StoreManager storeManager; | ||
private static String partitionName1 = "p1"; | ||
private static PartitionStateChangeListener fileCopyManagerListener; | ||
private static PartitionStateChangeListener storageManagerListener; | ||
private static ClusterParticipant primaryClusterParticipant; | ||
|
||
@BeforeClass | ||
public static void initialize() { | ||
storeConfig = mock(StoreConfig.class); | ||
storeManager = mock(StoreManager.class); | ||
primaryClusterParticipant = mock(ClusterParticipant.class); | ||
|
||
fileCopyManagerListener = mock(PartitionStateChangeListener.class); | ||
|
||
storageManagerListener = mock(PartitionStateChangeListener.class); | ||
|
||
Map<StateModelListenerType, PartitionStateChangeListener> partitionStateChangeListeners = | ||
new HashMap<StateModelListenerType, PartitionStateChangeListener>() { | ||
{ | ||
put(StateModelListenerType.FileCopyManagerListener, fileCopyManagerListener); | ||
put(StateModelListenerType.StorageManagerListener, storageManagerListener); | ||
} | ||
}; | ||
when(primaryClusterParticipant.getPartitionStateChangeListeners()) | ||
.thenReturn(partitionStateChangeListeners); | ||
|
||
when(primaryClusterParticipant.getReplicaSyncUpManager()) | ||
.thenReturn(mock(ReplicaSyncUpManager.class)); | ||
} | ||
|
||
@Test | ||
public void test__ReplicationProtocolTransitionType__NEW_PARTITION_TO_FILE_BASED_BOOTSTRAP() { | ||
// Arrange | ||
final BootstrapController.BootstrapControllerImpl bootstrapControllerImpl = | ||
getBootstrapControllerImpl(ServerReplicationMode.FILE_BASED); | ||
|
||
when(storeManager.getReplica(partitionName1)).thenReturn(null); | ||
|
||
// Act | ||
bootstrapControllerImpl.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
|
||
// Assert | ||
verify(fileCopyManagerListener, times(1)) | ||
.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
verify(storageManagerListener, never()) | ||
.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
|
||
assert bootstrapControllerImpl.replicationProtocolTransitionType.size() == 1; | ||
assert bootstrapControllerImpl.replicationProtocolTransitionType.contains( | ||
ReplicationProtocolTransitionType.NEW_PARTITION_TO_FILE_BASED_BOOTSTRAP); | ||
} | ||
|
||
@Test | ||
public void test__ReplicationProtocolTransitionType__NEW_PARTITION_TO_BLOB_BASED_BOOTSTRAP() { | ||
// Arrange | ||
final BootstrapController.BootstrapControllerImpl bootstrapControllerImpl = | ||
getBootstrapControllerImpl(ServerReplicationMode.BLOB_BASED); | ||
|
||
when(storeManager.getReplica(partitionName1)).thenReturn(null); | ||
|
||
// Act | ||
bootstrapControllerImpl.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
|
||
// Assert | ||
verify(fileCopyManagerListener, never()) | ||
.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
verify(storageManagerListener, times(1)) | ||
.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
|
||
assert bootstrapControllerImpl.replicationProtocolTransitionType.size() == 1; | ||
assert bootstrapControllerImpl.replicationProtocolTransitionType.contains( | ||
ReplicationProtocolTransitionType.NEW_PARTITION_TO_BLOB_BASED_BOOTSTRAP); | ||
} | ||
|
||
@Test | ||
public void test__ReplicationProtocolTransitionType__BLOB_BASED_COMPLETE_TO_FILE_BASED_BOOTSTRAP() { | ||
// Arrange | ||
final BootstrapController.BootstrapControllerImpl bootstrapControllerImpl = | ||
getBootstrapControllerImpl(ServerReplicationMode.FILE_BASED); | ||
|
||
TestReplica testReplica = mock(TestReplica.class); | ||
PartitionId partitionId = mock(PartitionId.class); | ||
when(testReplica.getPartitionId()).thenReturn(partitionId); | ||
when(storeManager.getReplica(partitionName1)).thenReturn(testReplica); | ||
when(storeManager.isFileExists(partitionId, storeConfig.storeBootstrapInProgressFile)) | ||
.thenReturn(true); | ||
|
||
// Act | ||
bootstrapControllerImpl.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
|
||
// Assert | ||
verify(fileCopyManagerListener, never()) | ||
.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
verify(storageManagerListener, times(1)) | ||
.onPartitionBecomeBootstrapFromOffline(partitionName1); | ||
|
||
assert bootstrapControllerImpl.replicationProtocolTransitionType.size() == 1; | ||
assert bootstrapControllerImpl.replicationProtocolTransitionType.contains( | ||
ReplicationProtocolTransitionType.BLOB_BASED_INCOMPLETE_TO_FILE_BASED_BOOTSTRAP); | ||
} | ||
|
||
private static BootstrapController.BootstrapControllerImpl getBootstrapControllerImpl( | ||
ServerReplicationMode serverReplicationMode) { | ||
|
||
Properties props = new Properties(); | ||
props.setProperty("server.replication.protocol.for.hydration", String.valueOf(serverReplicationMode)); | ||
serverConfig = new ServerConfig(new VerifiableProperties(props)); | ||
|
||
return new BootstrapController(storeManager, storeConfig, serverConfig, primaryClusterParticipant) | ||
.new BootstrapControllerImpl(); | ||
} | ||
} |