Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11959. Remove tests for non-Ratis SCM #7612

Merged
merged 17 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto.Type;
import org.apache.hadoop.hdds.protocol.proto
.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdds.scm.HddsTestUtils;
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ContainerManager;
Expand Down Expand Up @@ -112,7 +111,6 @@ public class TestDeletedBlockLog {
@BeforeEach
public void setup() throws Exception {
conf = new OzoneConfiguration();
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, true);
conf.setInt(OZONE_SCM_BLOCK_DELETION_MAX_RETRY, 20);
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getAbsolutePath());
replicationManager = mock(ReplicationManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
package org.apache.hadoop.hdds.scm.ha;

import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.ConfigurationException;
import org.apache.hadoop.hdds.conf.DefaultConfigManager;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdds.scm.ScmRatisServerConfig;
import org.apache.hadoop.hdds.scm.server.SCMStorageConfig;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.hdds.utils.HddsServerUtil;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.common.Storage;
Expand All @@ -35,13 +33,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.UUID;

import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_ADDRESS_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_ADDRESS_KEY;
Expand All @@ -63,16 +58,14 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_SECURITY_SERVICE_PORT_KEY;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_METADATA_DIRS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* Test for SCM HA-related configuration.
*/
class TestSCMHAConfiguration {
class TestSCMConfiguration {
private OzoneConfiguration conf;
@TempDir
private File tempDir;
Expand All @@ -85,7 +78,7 @@ void setup() {
}

@Test
public void testSCMHAConfig() throws Exception {
public void testSCMConfig() throws Exception {
String scmServiceId = "scmserviceId";
conf.set(ScmConfigKeys.OZONE_SCM_SERVICE_IDS_KEY, scmServiceId);

Expand Down Expand Up @@ -225,7 +218,7 @@ public void testSCMHAConfig() throws Exception {


@Test
public void testHAWithSamePortConfig() throws Exception {
public void testSamePortConfig() throws Exception {
String scmServiceId = "scmserviceId";
conf.set(ScmConfigKeys.OZONE_SCM_SERVICE_IDS_KEY, scmServiceId);

Expand Down Expand Up @@ -301,25 +294,7 @@ public void testHAWithSamePortConfig() throws Exception {
}

@Test
public void testRatisEnabledDefaultConfigWithoutInitializedSCM()
throws IOException {
SCMStorageConfig scmStorageConfig = mock(SCMStorageConfig.class);
when(scmStorageConfig.getState()).thenReturn(Storage.StorageState.NOT_INITIALIZED);
SCMHANodeDetails.loadSCMHAConfig(conf, scmStorageConfig);
assertEquals(SCMHAUtils.isSCMHAEnabled(conf),
ScmConfigKeys.OZONE_SCM_HA_ENABLE_DEFAULT);
DefaultConfigManager.clearDefaultConfigs();
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, false);
SCMHANodeDetails.loadSCMHAConfig(conf, scmStorageConfig);
assertFalse(SCMHAUtils.isSCMHAEnabled(conf));
DefaultConfigManager.clearDefaultConfigs();
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, true);
SCMHANodeDetails.loadSCMHAConfig(conf, scmStorageConfig);
assertTrue(SCMHAUtils.isSCMHAEnabled(conf));
}

@Test
public void testRatisEnabledDefaultConfigWithInitializedSCM()
public void testDefaultConfigWithInitializedSCM()
throws IOException {
SCMStorageConfig scmStorageConfig = mock(SCMStorageConfig.class);
when(scmStorageConfig.getState())
Expand All @@ -333,44 +308,4 @@ public void testRatisEnabledDefaultConfigWithInitializedSCM()
DefaultConfigManager.clearDefaultConfigs();
assertTrue(SCMHAUtils.isSCMHAEnabled(conf));
}

@Test
public void testRatisEnabledDefaultConflictConfigWithInitializedSCM() {
SCMStorageConfig scmStorageConfig = mock(SCMStorageConfig.class);
when(scmStorageConfig.getState())
.thenReturn(Storage.StorageState.INITIALIZED);
when(scmStorageConfig.isSCMHAEnabled()).thenReturn(true);
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, false);
assertThrows(ConfigurationException.class,
() -> SCMHANodeDetails.loadSCMHAConfig(conf, scmStorageConfig));
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
void testHAConfig(boolean ratisEnabled) throws IOException {
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, ratisEnabled);
SCMStorageConfig scmStorageConfig = newStorageConfig(ratisEnabled);
StorageContainerManager.scmInit(conf, scmStorageConfig.getClusterID());
assertEquals(ratisEnabled, DefaultConfigManager.getValue(
ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, !ratisEnabled));
}

@Test
void testInvalidHAConfig() throws IOException {
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, false);
SCMStorageConfig scmStorageConfig = newStorageConfig(true);
String clusterID = scmStorageConfig.getClusterID();
assertThrows(ConfigurationException.class,
() -> StorageContainerManager.scmInit(conf, clusterID));
}

private SCMStorageConfig newStorageConfig(
boolean ratisEnabled) throws IOException {
final SCMStorageConfig scmStorageConfig = new SCMStorageConfig(conf);
scmStorageConfig.setClusterId(UUID.randomUUID().toString());
scmStorageConfig.setSCMHAFlag(ratisEnabled);
scmStorageConfig.initialize();
return scmStorageConfig;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.google.protobuf.ByteString;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition;
import org.apache.hadoop.hdds.utils.db.DBStore;
import org.apache.hadoop.hdds.utils.db.DBStoreBuilder;
Expand Down Expand Up @@ -48,7 +47,6 @@ public class TestStatefulServiceStateManagerImpl {
@BeforeEach
void setup(@TempDir File testDir) throws IOException {
conf = SCMTestUtils.getConf(testDir);
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, true);
dbStore = DBStoreBuilder.createDBStore(conf, SCMDBDefinition.get());
statefulServiceConfig =
SCMDBDefinition.STATEFUL_SERVICE_CONFIG.getTable(dbStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ OzoneConfiguration getConf() {
TimeUnit.MILLISECONDS);
conf.setBoolean(HddsConfigKeys.HDDS_SCM_SAFEMODE_PIPELINE_CREATION, false);
conf.setInt(OZONE_SCM_RATIS_PIPELINE_LIMIT, 10);
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, true);
return conf;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.hadoop.hdds.scm.upgrade;

import org.apache.hadoop.hdds.conf.ConfigurationException;
import org.apache.hadoop.hdds.conf.DefaultConfigManager;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.HddsTestUtils;
Expand All @@ -26,19 +25,16 @@
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.ozone.upgrade.UpgradeException;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer;
import org.apache.ratis.util.ExitUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import java.nio.file.Path;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
Expand All @@ -62,64 +58,30 @@ public static void setup() {
ExitUtils.disableSystemExit();
}

@ParameterizedTest
@CsvSource({
"true, true",
"true, false",
"false, true",
"false, false",
})
public void testUpgrade(boolean haEnabledBefore,
boolean haEnabledPreFinalized, @TempDir Path dataPath) throws Exception {
@Test
public void testUpgrade(@TempDir Path dataPath) throws Exception {
// Write version file for original version.
OzoneConfiguration conf = new OzoneConfiguration();
conf.setInt(ScmConfig.ConfigStrings.HDDS_SCM_INIT_DEFAULT_LAYOUT_VERSION,
HDDSLayoutFeature.INITIAL_VERSION.layoutVersion());
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, haEnabledBefore);
conf.set(ScmConfigKeys.OZONE_SCM_DB_DIRS, dataPath.toString());
conf.set(OzoneConfigKeys.OZONE_METADATA_DIRS, dataPath.toString());
// This init should always succeed, since SCM is not pre-finalized yet.
DefaultConfigManager.clearDefaultConfigs();
boolean initResult1 = StorageContainerManager.scmInit(conf, CLUSTER_ID);
assertTrue(initResult1);

// Set up new pre-finalized SCM.
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY,
haEnabledPreFinalized);
/* Clusters from Ratis SCM -> Non Ratis SCM
Ratis SCM -> Non Ratis SCM not supported
*/
if (haEnabledPreFinalized != haEnabledBefore) {
if (haEnabledBefore) {
assertThrows(ConfigurationException.class,
() -> StorageContainerManager.scmInit(conf, CLUSTER_ID));
} else {
assertThrows(UpgradeException.class,
() -> StorageContainerManager.scmInit(conf, CLUSTER_ID));
}
return;
}
StorageContainerManager scm = HddsTestUtils.getScm(conf);

assertEquals(UpgradeFinalizer.Status.FINALIZATION_REQUIRED,
scm.getFinalizationManager().getUpgradeFinalizer().getStatus());

final boolean shouldFail = !haEnabledBefore && haEnabledPreFinalized;

DefaultConfigManager.clearDefaultConfigs();
if (shouldFail) {
// Start on its own should fail.
assertThrows(UpgradeException.class, scm::start);
boolean initResult2 = StorageContainerManager.scmInit(conf, CLUSTER_ID);
assertTrue(initResult2);
scm.start();
scm.stop();

// Init followed by start should both fail.
// Init is not necessary here, but is allowed to be run.
assertThrows(UpgradeException.class,
() -> StorageContainerManager.scmInit(conf, CLUSTER_ID));
assertThrows(UpgradeException.class, scm::start);
} else {
boolean initResult2 = StorageContainerManager.scmInit(conf, CLUSTER_ID);
assertTrue(initResult2);
scm.start();
scm.stop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class TestSCMInstallSnapshot {
@BeforeAll
static void setup(@TempDir Path tempDir) throws Exception {
conf = new OzoneConfiguration();
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, true);
conf.set(ScmConfigKeys.OZONE_SCM_PIPELINE_CREATION_INTERVAL, "10s");
conf.setLong(ScmConfigKeys.OZONE_SCM_HA_RATIS_SNAPSHOT_THRESHOLD, 1L);
conf.set(ScmConfigKeys.OZONE_SCM_HA_RATIS_SNAPSHOT_DIR, tempDir.toString());
Expand Down Expand Up @@ -105,7 +104,7 @@ private DBCheckpoint downloadSnapshot() throws Exception {
pipelineManager.openPipeline(ratisPipeline2.getId());
SCMNodeDetails scmNodeDetails = new SCMNodeDetails.Builder()
.setRpcAddress(new InetSocketAddress("0.0.0.0", 0))
.setGrpcPort(ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT)
.setGrpcPort(conf.getInt(ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY, ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT))
.setSCMNodeId("scm1")
.build();
Map<String, SCMNodeDetails> peerMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class TestSCMSnapshot {
@BeforeAll
public static void setup() throws Exception {
conf = new OzoneConfiguration();
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, true);
conf.set(ScmConfigKeys.OZONE_SCM_PIPELINE_CREATION_INTERVAL, "10s");
conf.setLong(ScmConfigKeys.OZONE_SCM_HA_RATIS_SNAPSHOT_THRESHOLD, 1L);
cluster = MiniOzoneCluster
Expand Down
Loading
Loading