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
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,21 @@
import org.apache.hadoop.ozone.ha.ConfUtils;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_ADDRESS_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_PORT_DEFAULT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CLIENT_PORT_DEFAULT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CLIENT_PORT_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_NAMES;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import static org.junit.jupiter.api.Assertions.fail;

/**
* This test class verifies the parsing of SCM endpoint config settings. The
Expand Down Expand Up @@ -130,8 +127,8 @@ private void checkAddr(OzoneConfiguration conf, String address, int port) {
HddsUtils.getScmAddressForClients(conf).iterator();
assertTrue(scmAddrIterator.hasNext());
InetSocketAddress scmAddr = scmAddrIterator.next();
assertThat(scmAddr.getHostString(), is(address));
assertThat(scmAddr.getPort(), is(port));
assertEquals(address, scmAddr.getHostString());
assertEquals(port, scmAddr.getPort());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import org.junit.jupiter.api.Test;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
Expand All @@ -36,8 +35,8 @@ public void testInvalidProtocolBuffer() throws Exception {
InvalidProtocolBufferException exception =
assertThrows(InvalidProtocolBufferException.class,
() -> getCodec().fromPersistedFormat("random".getBytes(UTF_8)));
assertThat(exception.getMessage(),
containsString("the input ended unexpectedly"));
assertThat(exception.getMessage())
.contains("the input ended unexpectedly");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

import java.io.StringWriter;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

/**
* Test the utility which loads/writes the config file fragments.
Expand All @@ -40,11 +39,9 @@ public void testInit() {

StringWriter builder = new StringWriter();
appender.write(builder);
assertThat("Generated config should contain property key entry",
builder.toString(),
containsString("<name>hadoop.scm.enabled</name>"));
assertThat("Generated config should contain tags",
builder.toString(),
containsString("<tag>OZONE, SECURITY</tag>"));

assertThat(builder.toString())
.contains("<name>hadoop.scm.enabled</name>")
.contains("<tag>OZONE, SECURITY</tag>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

/**
* Test the ConfigFileGenerator.
Expand All @@ -44,22 +43,19 @@ public void testGeneratedXml() throws FileNotFoundException {
.useDelimiter("//Z")
.next();

assertThat("Generated config should have entry based on the annotation",
generatedXml,
containsString("<name>ozone.scm.client.bind.host</name>"));
assertThat(generatedXml)
.as("annotation in ConfigurationExample")
.contains("<name>ozone.scm.client.bind.host</name>");

assertThat("Generated config should have entry based on the annotation " +
"from the parent class",
generatedXml,
containsString("<name>ozone.scm.client.secure</name>"));
assertThat(generatedXml)
.as("annotation in ConfigurationExampleParent")
.contains("<name>ozone.scm.client.secure</name>");

assertThat("Generated config should have entry based on the annotation " +
"from the grand-parent class.",
generatedXml,
containsString("<name>ozone.scm.client.number</name>"));
assertThat(generatedXml)
.as("annotation in ConfigurationExampleGrandParent")
.contains("<name>ozone.scm.client.number</name>");

assertThat("Generated config should contain tags",
generatedXml,
containsString("<tag>MANAGEMENT</tag>"));
assertThat(generatedXml)
.contains("<tag>MANAGEMENT</tag>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@

import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Result.BCSID_MISMATCH;
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Result.UNKNOWN_BCSID;
import static org.apache.hadoop.ozone.container.ContainerTestHelper.getChunk;
import static org.apache.hadoop.ozone.container.ContainerTestHelper.getData;
import static org.apache.hadoop.ozone.container.ContainerTestHelper.setDataChecksum;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;

import static org.apache.hadoop.ozone.container.keyvalue.helpers.KeyValueContainerUtil.isSameSchemaVersion;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -101,12 +102,6 @@
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Simple tests to verify that container persistence works as expected. Some of
* these tests are specific to {@link KeyValueContainer}. If a new {@link
Expand Down Expand Up @@ -290,8 +285,8 @@ public void testAddingBlockToDeletedContainer(
someKey.setChunks(new LinkedList<>());
Exception exception = assertThrows(StorageContainerException.class,
() -> blockManager.putBlock(container, someKey));
assertThat(exception.getMessage(),
Matchers.containsString("Error opening DB."));
assertThat(exception.getMessage())
.contains("Error opening DB.");
}

@ContainerTestVersionInfo.ContainerTest
Expand Down Expand Up @@ -327,9 +322,8 @@ public void testDeleteNonEmptyContainer(ContainerTestVersionInfo versionInfo)
() -> kvHandler.deleteContainer(container, false));
assertThat(containerSet.getContainerMapCopy())
.containsKey(testContainerID);
assertThat(exception.getMessage(),
Matchers.containsString(
"Non-force deletion of non-empty container is not allowed."));
assertThat(exception.getMessage())
.contains("Non-force deletion of non-empty container is not allowed.");
}

@ContainerTestVersionInfo.ContainerTest
Expand Down Expand Up @@ -1016,7 +1010,7 @@ public void testListBlock(ContainerTestVersionInfo versionInfo)
// Count must be >0
Exception exception = assertThrows(IllegalArgumentException.class,
() -> blockManager.listBlock(container, 0, -1));
assertThat(exception.getMessage(),
Matchers.containsString("Count must be a positive number."));
assertThat(exception.getMessage())
.contains("Count must be a positive number.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.NodeReportProto;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CRLStatusReport;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -75,7 +74,7 @@ public void testInvalidReportPublisher() {
RuntimeException.class,
() -> factory.getPublisherFor(HddsProtos.DatanodeDetailsProto.class)
);
MatcherAssert.assertThat(runtimeException.getMessage(),
Matchers.containsString("No publisher found for report"));
assertThat(runtimeException.getMessage())
.contains("No publisher found for report");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
import java.util.concurrent.atomic.AtomicLong;

import static org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult.FAILED;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Matchers.anyObject;
Expand Down Expand Up @@ -151,11 +150,11 @@ public void testCheckOneVolume(
numCallbackInvocations.incrementAndGet();
if (expectedVolumeHealth != null &&
expectedVolumeHealth != FAILED) {
assertThat(healthyVolumes.size(), is(1));
assertThat(failedVolumes.size(), is(0));
assertThat(healthyVolumes.size()).isEqualTo(1);
assertThat(failedVolumes.size()).isEqualTo(0);
} else {
assertThat(healthyVolumes.size(), is(0));
assertThat(failedVolumes.size(), is(1));
assertThat(healthyVolumes.size()).isEqualTo(0);
assertThat(failedVolumes.size()).isEqualTo(1);
}
});

Expand All @@ -164,7 +163,7 @@ public void testCheckOneVolume(
// Ensure that the check was invoked at least once.
verify(volume, times(1)).check(anyObject());
if (result) {
assertThat(numCallbackInvocations.get(), is(1L));
assertThat(numCallbackInvocations.get()).isEqualTo(1L);
}

checker.shutdownAndWait(0, TimeUnit.SECONDS);
Expand Down Expand Up @@ -194,7 +193,7 @@ public void testCheckAllVolumes(VolumeCheckResult checkResult,
LOG.info("Got back {} failed volumes", failedVolumes.size());

if (expectedVolumeHealth == null || expectedVolumeHealth == FAILED) {
assertThat(failedVolumes.size(), is(NUM_VOLUMES));
assertThat(failedVolumes.size()).isEqualTo(NUM_VOLUMES);
} else {
assertTrue(failedVolumes.isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import org.apache.commons.io.FileUtils;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.hamcrest.CoreMatchers.is;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -108,9 +107,8 @@ public void testOzoneDirsAreCreated() throws IOException {
new MutableVolumeSet(UUID.randomUUID().toString(), conf,
null, StorageVolume.VolumeType.DATA_VOLUME, null);

MatcherAssert.assertThat(volumeSet.getVolumesList().size(), is(numVolumes));
MatcherAssert.assertThat(
volumeSet.getFailedVolumesList().size(), is(0));
assertThat(volumeSet.getVolumesList().size()).isEqualTo(numVolumes);
assertThat(volumeSet.getFailedVolumesList().size()).isEqualTo(0);

// Verify that the Ozone dirs were created during initialization.
Collection<String> dirs = conf.getTrimmedStringCollection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State.OPEN;
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State.UNHEALTHY;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyLong;
Expand Down Expand Up @@ -122,16 +121,16 @@ public void teardown() {
@ContainerLayoutTestInfo.ContainerTest
public void testMarkContainerUnhealthy(ContainerLayoutVersion layoutVersion) throws Exception {
initTestData(layoutVersion);
assertThat(keyValueContainerData.getState(), is(OPEN));
assertThat(keyValueContainerData.getState()).isEqualTo(OPEN);
keyValueContainer.markContainerUnhealthy();
assertThat(keyValueContainerData.getState(), is(UNHEALTHY));
assertThat(keyValueContainerData.getState()).isEqualTo(UNHEALTHY);

// Check metadata in the .container file
File containerFile = keyValueContainer.getContainerFile();

keyValueContainerData = (KeyValueContainerData) ContainerDataYaml
.readContainerFile(containerFile);
assertThat(keyValueContainerData.getState(), is(UNHEALTHY));
assertThat(keyValueContainerData.getState()).isEqualTo(UNHEALTHY);
}

/**
Expand Down Expand Up @@ -159,7 +158,7 @@ public void testMarkClosedContainerAsUnhealthy(ContainerLayoutVersion layoutVers
keyValueContainer.create(volumeSet, volumeChoosingPolicy, scmId);
keyValueContainer.close();
keyValueContainer.markContainerUnhealthy();
assertThat(keyValueContainerData.getState(), is(UNHEALTHY));
assertThat(keyValueContainerData.getState()).isEqualTo(UNHEALTHY);
}

/**
Expand All @@ -173,7 +172,7 @@ public void testMarkQuasiClosedContainerAsUnhealthy(ContainerLayoutVersion layou
keyValueContainer.create(volumeSet, volumeChoosingPolicy, scmId);
keyValueContainer.quasiClose();
keyValueContainer.markContainerUnhealthy();
assertThat(keyValueContainerData.getState(), is(UNHEALTHY));
assertThat(keyValueContainerData.getState()).isEqualTo(UNHEALTHY);
}

/**
Expand All @@ -184,6 +183,6 @@ public void testMarkClosingContainerAsUnhealthy(ContainerLayoutVersion layoutVer
initTestData(layoutVersion);
keyValueContainer.markContainerForClose();
keyValueContainer.markContainerUnhealthy();
assertThat(keyValueContainerData.getState(), is(UNHEALTHY));
assertThat(keyValueContainerData.getState()).isEqualTo(UNHEALTHY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@

import java.security.cert.X509Certificate;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItemInArray;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

Expand All @@ -53,17 +50,16 @@ public void testReload() throws Exception {
(ReloadingX509TrustManager) caClient.getServerKeyStoresFactory()
.getTrustManagers()[0];
X509Certificate cert1 = caClient.getRootCACertificate();
assertThat(tm.getAcceptedIssuers(), arrayContaining(cert1));
assertThat(tm.getAcceptedIssuers()).containsOnly(cert1);

caClient.renewRootCA();
caClient.renewKey();
X509Certificate cert2 = caClient.getRootCACertificate();
assertNotEquals(cert1, cert2);

assertThat(tm.getAcceptedIssuers(), hasItemInArray(cert1));
assertThat(tm.getAcceptedIssuers(), hasItemInArray(cert2));
assertThat(reloaderLog.getOutput(),
containsString("ReloadingX509TrustManager is reloaded"));
assertThat(tm.getAcceptedIssuers()).contains(cert1, cert2);
assertThat(reloaderLog.getOutput())
.contains("ReloadingX509TrustManager is reloaded");

// Make sure there are two reload happened, one for server, one for client
assertEquals(2, StringUtils.countMatches(reloaderLog.getOutput(),
Expand Down
Loading