diff --git a/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/GenericTestUtils.java b/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/GenericTestUtils.java index 406a58768a84..92e059296c0e 100644 --- a/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/GenericTestUtils.java +++ b/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/GenericTestUtils.java @@ -24,6 +24,7 @@ import java.io.PrintStream; import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import java.time.Instant; import java.util.List; import java.util.Map; import java.util.concurrent.TimeoutException; @@ -73,6 +74,18 @@ public abstract class GenericTestUtils { "target" + File.separator + "test" + File.separator + "data"; } + /** + * Return current time in millis as an {@code Instant}. This may be + * before {@link Instant#now()}, since the latter includes nanoseconds, too. + * This is needed for some tests that verify volume/bucket creation time, + * which also uses {@link Instant#ofEpochMilli(long)}. + * + * @return current time as {@code Instant}; + */ + public static Instant getTestStartTime() { + return Instant.ofEpochMilli(System.currentTimeMillis()); + } + /** * Get the (created) base directory for tests. * diff --git a/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/TestOzoneClient.java b/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/TestOzoneClient.java index 42b9d8076710..fc10143a4705 100644 --- a/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/TestOzoneClient.java +++ b/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/TestOzoneClient.java @@ -47,6 +47,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.hadoop.hdds.client.ReplicationFactor.ONE; +import static org.apache.ozone.test.GenericTestUtils.getTestStartTime; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -138,7 +139,7 @@ public void testCreateVolumeWithMetadata() @Test public void testCreateBucket() throws IOException { - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); store.createVolume(volumeName); @@ -152,7 +153,7 @@ public void testCreateBucket() @Test public void testPutKeyRatisOneNode() throws IOException { - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String value = "sample value"; OzoneBucket bucket = getOzoneBucket(); diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneAtRestEncryption.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneAtRestEncryption.java index ab09bc24330f..08df9c941144 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneAtRestEncryption.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneAtRestEncryption.java @@ -78,6 +78,7 @@ import static org.apache.hadoop.hdds.HddsConfigKeys.OZONE_METADATA_DIRS; import static org.apache.hadoop.hdds.client.ReplicationFactor.ONE; import static org.apache.hadoop.hdds.client.ReplicationType.RATIS; +import static org.apache.ozone.test.GenericTestUtils.getTestStartTime; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -229,7 +230,7 @@ void testLinkEncryptedBuckets(BucketLayout bucketLayout) throws Exception { static void createAndVerifyStreamKeyData(OzoneBucket bucket) throws Exception { - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String keyName = UUID.randomUUID().toString(); String value = "sample value"; try (OzoneDataStreamOutput out = bucket.createStreamKey(keyName, @@ -242,7 +243,7 @@ static void createAndVerifyStreamKeyData(OzoneBucket bucket) } static void createAndVerifyKeyData(OzoneBucket bucket) throws Exception { - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String keyName = UUID.randomUUID().toString(); String value = "sample value"; try (OzoneOutputStream out = bucket.createKey(keyName, @@ -318,7 +319,7 @@ void testKeyWithEncryptionAndGdpr(BucketLayout bucketLayout) //Step 1 String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String value = "sample value"; store.createVolume(volumeName); diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java index 4e0c9bbf5b10..05c957d78285 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java @@ -144,6 +144,7 @@ import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.READ; import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.WRITE; +import static org.apache.ozone.test.GenericTestUtils.getTestStartTime; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -583,7 +584,7 @@ public void testCreateBucketWithMetadata() @Test public void testCreateBucket() throws IOException { - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); store.createVolume(volumeName); @@ -598,7 +599,7 @@ public void testCreateBucket() @Test public void testCreateS3Bucket() throws IOException { - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String bucketName = UUID.randomUUID().toString(); store.createS3Bucket(bucketName); OzoneBucket bucket = store.getS3Bucket(bucketName); @@ -610,7 +611,7 @@ public void testCreateS3Bucket() @Test public void testDeleteS3Bucket() throws Exception { - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String bucketName = UUID.randomUUID().toString(); store.createS3Bucket(bucketName); OzoneBucket bucket = store.getS3Bucket(bucketName); @@ -1005,7 +1006,7 @@ public void testPutKeyWithReplicationConfig(String replicationValue, public void testPutKey() throws IOException { String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String value = "sample value"; store.createVolume(volumeName); @@ -1545,7 +1546,7 @@ public void testValidateBlockLengthWithCommitKey() throws IOException { public void testPutKeyRatisOneNode() throws IOException { String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String value = "sample value"; store.createVolume(volumeName); @@ -1580,7 +1581,7 @@ public void testPutKeyRatisOneNode() throws IOException { public void testPutKeyRatisThreeNodes() throws IOException { String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); String value = "sample value"; store.createVolume(volumeName); @@ -1617,7 +1618,7 @@ public void testPutKeyRatisThreeNodesParallel() throws IOException, InterruptedException { String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); store.createVolume(volumeName); OzoneVolume volume = store.getVolume(volumeName); volume.createBucket(bucketName); diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestSecureOzoneRpcClient.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestSecureOzoneRpcClient.java index e8aece20f4fd..548b1b303501 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestSecureOzoneRpcClient.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestSecureOzoneRpcClient.java @@ -76,6 +76,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.hadoop.hdds.HddsConfigKeys.OZONE_METADATA_DIRS; +import static org.apache.ozone.test.GenericTestUtils.getTestStartTime; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -166,7 +167,7 @@ private void testPutKeySuccessWithBlockTokenWithBucketLayout( BucketLayout bucketLayout) throws Exception { String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager(); String value = "sample value"; diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestStorageContainerManagerHA.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestStorageContainerManagerHA.java index a0f5bc7834e0..323db6605a32 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestStorageContainerManagerHA.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestStorageContainerManagerHA.java @@ -60,6 +60,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.hadoop.hdds.client.ReplicationFactor.ONE; import static org.apache.hadoop.hdds.client.ReplicationType.RATIS; +import static org.apache.ozone.test.GenericTestUtils.getTestStartTime; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -175,7 +176,7 @@ void testAllSCMAreRunning() throws Exception { private void doPutKey() throws Exception { String volumeName = UUID.randomUUID().toString(); String bucketName = UUID.randomUUID().toString(); - Instant testStartTime = Instant.now(); + Instant testStartTime = getTestStartTime(); try (OzoneClient client = cluster.newClient()) { ObjectStore store = client.getObjectStore(); String value = "sample value";