Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions hadoop-hdds/framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,33 @@
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.ozone.test.GenericTestUtils;
import org.bouncycastle.cert.X509CertificateHolder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;
import java.util.stream.Stream;

import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_METADATA_DIR_NAME;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse.FAILURE;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse.GETCERT;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse.RECOVER;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse.SUCCESS;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments;

/**
* Test class for {@link DefaultCertificateClient}.
*/
@RunWith(Parameterized.class)
@SuppressWarnings("visibilitymodifier")
public class TestCertificateClientInit {

private KeyPair keyPair;
Expand All @@ -72,29 +70,20 @@ public class TestCertificateClientInit {
private static final String DN_COMPONENT = DNCertificateClient.COMPONENT_NAME;
private static final String OM_COMPONENT = OMCertificateClient.COMPONENT_NAME;

@Parameter
public boolean pvtKeyPresent;
@Parameter(1)
public boolean pubKeyPresent;
@Parameter(2)
public boolean certPresent;
@Parameter(3)
public InitResponse expectedResult;

@Parameterized.Parameters
public static Collection<Object[]> initData() {
return Arrays.asList(new Object[][]{
{false, false, false, GETCERT},
{false, false, true, FAILURE},
{false, true, false, FAILURE},
{true, false, false, FAILURE},
{false, true, true, FAILURE},
{true, true, false, GETCERT},
{true, false, true, SUCCESS},
{true, true, true, SUCCESS}});
private static Stream<Arguments> parameters() {
return Stream.of(
arguments(false, false, false, GETCERT),
arguments(false, false, true, FAILURE),
arguments(false, true, false, FAILURE),
arguments(true, false, false, FAILURE),
arguments(false, true, true, FAILURE),
arguments(true, true, false, GETCERT),
arguments(true, false, true, SUCCESS),
arguments(true, true, true, SUCCESS)
);
}

@Before
@BeforeEach
public void setUp() throws Exception {
OzoneConfiguration config = new OzoneConfiguration();
final String path = GenericTestUtils
Expand All @@ -117,16 +106,18 @@ public void setUp() throws Exception {
Files.createDirectories(securityConfig.getKeyLocation(OM_COMPONENT));
}

@After
@AfterEach
public void tearDown() {
dnCertificateClient = null;
omCertificateClient = null;
FileUtils.deleteQuietly(metaDirPath.toFile());
}


@Test
public void testInitDatanode() throws Exception {
@ParameterizedTest
@MethodSource("parameters")
public void testInitDatanode(boolean pvtKeyPresent, boolean pubKeyPresent,
boolean certPresent, InitResponse expectedResult) throws Exception {
if (pvtKeyPresent) {
dnKeyCodec.writePrivateKey(keyPair.getPrivate());
} else {
Expand Down Expand Up @@ -157,7 +148,7 @@ public void testInitDatanode() throws Exception {
}
InitResponse response = dnCertificateClient.init();

assertTrue(response.equals(expectedResult));
assertEquals(expectedResult, response);

if (!response.equals(FAILURE)) {
assertTrue(OzoneSecurityUtil.checkIfFileExist(
Expand All @@ -169,8 +160,10 @@ public void testInitDatanode() throws Exception {
}
}

@Test
public void testInitOzoneManager() throws Exception {
@ParameterizedTest
@MethodSource("parameters")
public void testInitOzoneManager(boolean pvtKeyPresent, boolean pubKeyPresent,
boolean certPresent, InitResponse expectedResult) throws Exception {
if (pvtKeyPresent) {
omKeyCodec.writePrivateKey(keyPair.getPrivate());
} else {
Expand Down Expand Up @@ -202,9 +195,9 @@ public void testInitOzoneManager() throws Exception {
InitResponse response = omCertificateClient.init();

if (pvtKeyPresent && pubKeyPresent && !certPresent) {
assertTrue(response.equals(RECOVER));
assertEquals(RECOVER, response);
} else {
assertTrue(response.equals(expectedResult));
assertEquals(expectedResult, response);
}

if (!response.equals(FAILURE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,24 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.params.provider.Arguments.arguments;

/**
* Test Ratis metrics renaming.
*/
@RunWith(Parameterized.class)
public class TestRatisNameRewrite {

private List<String> names = new ArrayList<>();
private List<String> values = new ArrayList<>();

private String originalName;
private String expectedName;

private List<String> expectedTagNames;
private List<String> expectedTagValues;

@Parameterized.Parameters
public static List<Object[]> parameters() {
return Arrays.asList(
new Object[] {
private static Stream<Arguments> parameters() {
return Stream.of(
arguments(
"ratis.log_appender"
+ ".851cb00a-af97-455a-b079-d94a77d2a936@group-C14654DE8C2C"
+ ".follower_65f881ea-8794-403d-be77-a030ed79c341_match_index",
Expand All @@ -53,8 +46,8 @@ public static List<Object[]> parameters() {
new String[] {"851cb00a-af97-455a-b079-d94a77d2a936",
"group-C14654DE8C2C",
"65f881ea-8794-403d-be77-a030ed79c341"}
},
new Object[] {
),
arguments(
"ratis_grpc.log_appender.72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67@group"
+ "-72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67"
+ ".grpc_log_appender_follower_75fa730a-59f0-4547"
Expand All @@ -64,24 +57,24 @@ public static List<Object[]> parameters() {
new String[] {"72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67",
"group-72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67",
"75fa730a-59f0-4547-bd68-216162c263eb"}
},
new Object[] {
),
arguments(
"ratis_core.ratis_log_worker.72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67"
+ ".dataQueueSize",
"ratis_core.ratis_log_worker.dataQueueSize",
new String[] {"instance"},
new String[] {"72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67"}
},
new Object[] {
),
arguments(
"ratis_grpc.log_appender.8e505d6e-12a4-4660-80e3-eb735879db06"
+ "@group-49616B7F02CE.grpc_log_appender_follower_a4b099a7"
+ "-511f-4fef-85bf-b9eeddd7c270_latency",
"ratis_grpc.log_appender.grpc_log_appender_follower_latency",
new String[] {"instance", "group", "follower"},
new String[] {"8e505d6e-12a4-4660-80e3-eb735879db06",
"group-49616B7F02CE", "a4b099a7-511f-4fef-85bf-b9eeddd7c270"}
},
new Object[] {
),
arguments(
"ratis_grpc.log_appender.8e505d6e-12a4-4660-80e3-eb735879db06"
+ "@group-49616B7F02CE.grpc_log_appender_follower_a4b099a7"
+ "-511f-4fef-85bf-b9eeddd7c270_success_reply_count",
Expand All @@ -90,28 +83,24 @@ public static List<Object[]> parameters() {
new String[] {"instance", "group", "follower"},
new String[] {"8e505d6e-12a4-4660-80e3-eb735879db06",
"group-49616B7F02CE", "a4b099a7-511f-4fef-85bf-b9eeddd7c270"}
}

)
);
}

public TestRatisNameRewrite(String originalName, String expectedName,
@ParameterizedTest
@MethodSource("parameters")
public void normalizeRatisMetricName(String originalName, String expectedName,
String[] expectedTagNames, String[] expectedTagValues) {
this.originalName = originalName;
this.expectedName = expectedName;
this.expectedTagNames = Arrays.asList(expectedTagNames);
this.expectedTagValues = Arrays.asList(expectedTagValues);
}

@Test
public void normalizeRatisMetricName() {
List<String> names = new ArrayList<>();
List<String> values = new ArrayList<>();

String cleanName = new RatisNameRewriteSampleBuilder()
.normalizeRatisMetric(originalName, names, values);

Assert.assertEquals(expectedName, cleanName);
Assert.assertEquals(expectedTagNames, names);
Assert.assertEquals(expectedTagValues, values);
Assertions.assertEquals(expectedName, cleanName);
Assertions.assertEquals(Arrays.asList(expectedTagNames), names);
Assertions.assertEquals(Arrays.asList(expectedTagValues), values);

}
}
Loading