Fix unit tests for java 17 (#14207)

Fix a unit test that fails in java 17
This commit is contained in:
George Shiqi Wu 2023-05-09 10:32:31 -04:00 committed by GitHub
parent bd0080c4ce
commit 161d12eb44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 3 deletions

View File

@ -43,6 +43,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
public class PodTemplateTaskAdapterTest
@ -137,7 +138,7 @@ public class PodTemplateTaskAdapterTest
Job actual = adapter.fromTask(task);
Job expected = K8sTestUtils.fileToResource("expectedNoopJob.yaml", Job.class);
Assertions.assertEquals(expected, actual);
assertJobSpecsEqual(actual, expected);
}
@Test
@ -179,7 +180,7 @@ public class PodTemplateTaskAdapterTest
Job actual = adapter.fromTask(task);
Job expected = K8sTestUtils.fileToResource("expectedNoopJobTlsEnabled.yaml", Job.class);
Assertions.assertEquals(expected, actual);
assertJobSpecsEqual(actual, expected);
}
@Test
@ -234,7 +235,7 @@ public class PodTemplateTaskAdapterTest
Job actual = adapter.fromTask(task);
Job expected = K8sTestUtils.fileToResource("expectedNoopJob.yaml", Job.class);
Assertions.assertEquals(expected, actual);
assertJobSpecsEqual(actual, expected);
}
@Test
@ -314,4 +315,24 @@ public class PodTemplateTaskAdapterTest
Assertions.assertEquals(expected, actual);
}
private void assertJobSpecsEqual(Job actual, Job expected) throws IOException
{
Map<String, String> actualAnnotations = actual.getSpec().getTemplate().getMetadata().getAnnotations();
String actualTaskAnnotation = actualAnnotations.get(DruidK8sConstants.TASK);
actualAnnotations.remove(DruidK8sConstants.TASK);
actual.getSpec().getTemplate().getMetadata().setAnnotations(actualAnnotations);
Map<String, String> expectedAnnotations = expected.getSpec().getTemplate().getMetadata().getAnnotations();
String expectedTaskAnnotation = expectedAnnotations.get(DruidK8sConstants.TASK);
expectedAnnotations.remove(DruidK8sConstants.TASK);
expected.getSpec().getTemplate().getMetadata().setAnnotations(expectedAnnotations);
Assertions.assertEquals(actual, expected);
Assertions.assertEquals(
Base64Compression.decompressBase64(actualTaskAnnotation),
Base64Compression.decompressBase64(expectedTaskAnnotation)
);
}
}