下面列出了org.testng.annotations.BeforeSuite#org.testng.SkipException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test(groups = {STORAGE_FORMATS, HIVE_TRANSACTIONAL})
public void testFailAcidBeforeHive3()
{
if (getHiveVersionMajor() >= 3) {
throw new SkipException("This tests behavior of ACID table before Hive 3 ");
}
try (TemporaryHiveTable table = TemporaryHiveTable.temporaryHiveTable("test_fail_acid_before_hive3_" + randomTableSuffix())) {
String tableName = table.getName();
onHive().executeQuery("" +
"CREATE TABLE " + tableName + "(a bigint) " +
"CLUSTERED BY(a) INTO 4 BUCKETS " +
"STORED AS ORC " +
"TBLPROPERTIES ('transactional'='true')");
assertThat(() -> query("SELECT * FROM " + tableName))
.failsWithMessage("Failed to open transaction. Transactional tables support requires Hive metastore version at least 3.0");
}
}
@Override
public void testColumnName(String columnName)
{
if (columnName.equals("atrailingspace ") || columnName.equals(" aleadingspace")) {
// TODO (https://github.com/prestosql/presto/issues/3461)
assertThatThrownBy(() -> super.testColumnName(columnName))
.hasMessageMatching("Table '.*' does not have columns \\[" + columnName + "]");
throw new SkipException("works incorrectly, column name is trimmed");
}
if (columnName.equals("a,comma")) {
// TODO (https://github.com/prestosql/presto/issues/3537)
assertThatThrownBy(() -> super.testColumnName(columnName))
.hasMessageMatching("Table '.*' does not have columns \\[a,comma]");
throw new SkipException("works incorrectly");
}
super.testColumnName(columnName);
}
private ZooModel<Image, DetectedObjects> getModel()
throws IOException, ModelNotFoundException, MalformedModelException {
if (!TestUtils.isMxnet()) {
throw new SkipException("SSD-pikachu model only available in MXNet");
}
Criteria<Image, DetectedObjects> criteria =
Criteria.builder()
.optApplication(Application.CV.OBJECT_DETECTION)
.setTypes(Image.class, DetectedObjects.class)
.optGroupId(BasicModelZoo.GROUP_ID)
.optArtifactId("ssd")
.optFilter("flavor", "tiny")
.optFilter("dataset", "pikachu")
.build();
return ModelZoo.loadModel(criteria);
}
private ZooModel<Image, Classifications> getModel()
throws IOException, ModelNotFoundException, MalformedModelException {
if (!TestUtils.isMxnet()) {
throw new SkipException("Resnet50-cifar10 model only available in MXNet");
}
Criteria<Image, Classifications> criteria =
Criteria.builder()
.optApplication(Application.CV.IMAGE_CLASSIFICATION)
.setTypes(Image.class, Classifications.class)
.optGroupId(BasicModelZoo.GROUP_ID)
.optArtifactId("resnet")
.optFilter("layers", "50")
.optFilter("dataset", "cifar10")
.build();
return ModelZoo.loadModel(criteria);
}
@Test
public void testFixedSeed() {
try (NDManager manager = NDManager.newBaseManager()) {
if (Engine.getInstance().getEngineName().equals("TensorFlow")) {
throw new SkipException("TensorFlow fixed random seed require restart process.");
}
int fixedSeed = 1234;
Engine.getInstance().setRandomSeed(fixedSeed);
NDArray expectedUniform = manager.randomUniform(-10, 10, new Shape(10, 10));
Engine.getInstance().setRandomSeed(fixedSeed);
NDArray actualUniform = manager.randomUniform(-10, 10, new Shape(10, 10));
Assertions.assertAlmostEquals(expectedUniform, actualUniform, 1e-2f, 1e-2f);
Engine.getInstance().setRandomSeed(fixedSeed);
NDArray expectedNormal = manager.randomNormal(new Shape(100, 100));
Engine.getInstance().setRandomSeed(fixedSeed);
NDArray actualNormal = manager.randomNormal(new Shape(100, 100));
Assertions.assertAlmostEquals(expectedNormal, actualNormal, 1e-2f, 1e-2f);
}
}
@Test
public void testTrainResNetSymbolicNightly()
throws ParseException, ModelException, IOException, TranslateException {
// this is nightly test
if (!Boolean.getBoolean("nightly")) {
throw new SkipException("Nightly only");
}
if (Device.getGpuCount() > 0) {
// Limit max 4 gpu for cifar10 training to make it converge faster.
// and only train 10 batch for unit test.
String[] args = {"-e", "10", "-g", "4", "-s", "-p"};
Engine.getInstance().setRandomSeed(SEED);
TrainingResult result = TrainResnetWithCifar10.runExample(args);
Assert.assertTrue(result.getTrainEvaluation("Accuracy") >= 0.8f);
Assert.assertTrue(result.getValidateEvaluation("Accuracy") >= 0.7f);
Assert.assertTrue(result.getValidateLoss() < 1.1);
}
}
@Test
public void testTrainResNetImperativeNightly()
throws ParseException, ModelException, IOException, TranslateException {
// this is nightly test
if (!Boolean.getBoolean("nightly")) {
throw new SkipException("Nightly only");
}
if (Device.getGpuCount() > 0) {
// Limit max 4 gpu for cifar10 training to make it converge faster.
// and only train 10 batch for unit test.
String[] args = {"-e", "10", "-g", "4"};
Engine.getInstance().setRandomSeed(SEED);
TrainingResult result = TrainResnetWithCifar10.runExample(args);
Assert.assertTrue(result.getTrainEvaluation("Accuracy") >= 0.9f);
Assert.assertTrue(result.getValidateEvaluation("Accuracy") >= 0.75f);
Assert.assertTrue(result.getValidateLoss() < 1);
}
}
@Test
private void executeTest() throws Exception {
System.out.println(testName);
if (mode.equals("forwards")) {
// I don't really know what mode=forwards means, but we fail them both
// and at least one of the two seems invalid to me
throw new SkipException("Skipping 'forwards' test " + testName);
}
try {
FHIRPathPatch patch = FHIRPathPatch.from(params);
// Set the id to match the expected parameters object so we can do a normal compare
Parameters serializedPatch = patch.toParameters().toBuilder().id(params.getId()).build();
assertEquals(serializedPatch, params);
Resource actualOutput = patch.apply(input);
assertEquals(actualOutput, expectedOutput);
} catch(UnsupportedOperationException e) {
throw new SkipException("Skipping '" + testName + "' due to an unsupported feature");
}
}
@Test
public void testFixFullUnionBranches() throws Exception {
if (AvroCompatibilityHelper.getRuntimeAvroVersion().laterThan(AvroVersion.AVRO_1_4)) {
throw new SkipException("test only valid under avro 1.4 and earlier");
}
String avsc = TestUtil.load("HasUnions.avsc");
String payload14 = TestUtil.load("HasUnions14.json");
String payload17 = TestUtil.load("HasUnions17.json");
LegacyAvroSchema schema = new LegacyAvroSchema("1234", avsc);
GenericRecord deserialized14 = schema.deserializeJson(payload14);
Assert.assertNotNull(deserialized14);
Assert.assertNotNull(deserialized14.get("f1"));
GenericRecord deserialized17 = schema.deserializeJson(payload17);
Assert.assertNotNull(deserialized17);
Assert.assertNotNull(deserialized17.get("f1"));
}
@Test
public void testVanilla14FixedClassesIncompatibleWithAvro17() throws Exception {
AvroVersion runtimeVersion = AvroCompatibilityHelper.getRuntimeAvroVersion();
if (!runtimeVersion.equals(AvroVersion.AVRO_1_7)) {
throw new SkipException("class only supported under avro 1.7. runtime version detected as " + runtimeVersion);
}
String sourceCode = TestUtil.load("Vanilla14Fixed");
Class clazz = CompilerUtils.CACHED_COMPILER.loadFromJava("com.acme.generatedby14.Vanilla14Fixed", sourceCode);
try {
clazz.newInstance();
Assert.fail("expecting an exception");
} catch (AvroRuntimeException expected) {
Assert.assertTrue(expected.getMessage().contains("Not a Specific class")); //fails to find SCHEMA$
}
}
@Test
public void testVanilla14FixedClassesIncompatibleWithModernAvro() throws Exception {
AvroVersion runtimeVersion = AvroCompatibilityHelper.getRuntimeAvroVersion();
if (!runtimeVersion.laterThan(AvroVersion.AVRO_1_7)) {
throw new SkipException("class only supported under modern avro. runtime version detected as " + runtimeVersion);
}
String sourceCode = TestUtil.load("Vanilla14Fixed");
StringWriter sr = new StringWriter();
PrintWriter compilerOutput = new PrintWriter(sr);
try {
Class aClass = CompilerUtils.CACHED_COMPILER.loadFromJava(getClass().getClassLoader(),
"com.acme.generatedby14.Vanilla14Fixed", sourceCode, compilerOutput);
Assert.fail("compilation expected to fail");
} catch (ClassNotFoundException ignored) {
//expected
}
String errorMsg = sr.toString();
Assert.assertTrue(errorMsg.contains("is not abstract and does not override")); //doesnt implement Externalizable
}
/**
* Create the files used by the test
*/
@BeforeSuite
public void setUp() throws Exception {
boolean supportsPosix = FileSystems.getDefault()
.supportedFileAttributeViews().contains("posix");
// Check to see if File System supports POSIX permissions
if (supportsPosix) {
System.out.println("File Store Supports Posix");
} else {
// As there is no POSIX permission support, skip running the test
throw new SkipException("Cannot set permissions on this File Store");
}
Files.write(entry0, "Tennis Pro".getBytes(UTF_8));
Files.write(entry1, "Tennis is a lifetime sport!".getBytes(UTF_8));
}
@Test
public void testFixShortUnionBranches() throws Exception {
if (!AvroCompatibilityHelper.getRuntimeAvroVersion().laterThan(AvroVersion.AVRO_1_4)) {
throw new SkipException("test only valid under modern avro");
}
String avsc = TestUtil.load("HasUnions.avsc");
String payload14 = TestUtil.load("HasUnions14.json");
String payload17 = TestUtil.load("HasUnions17.json");
LegacyAvroSchema schema = new LegacyAvroSchema("1234", avsc);
GenericRecord deserialized14 = schema.deserializeJson(payload14);
Assert.assertNotNull(deserialized14);
Assert.assertNotNull(deserialized14.get("f1"));
GenericRecord deserialized17 = schema.deserializeJson(payload17);
Assert.assertNotNull(deserialized17);
Assert.assertNotNull(deserialized17.get("f1"));
}
/**
* Validates if the test case is one that should be executed on the running product version.
* <p>
* All test methods of the test case will be skipped if it is not compatible with the running version. This is
* introduced to cater tests introduced for fixes done as patches for released product versions as they may only
* be valid for the product version for which the fix was done for.
*
* @param incompatibleVersions product versions that the test is not compatible with
*/
protected void skipTestsForIncompatibleProductVersions(String... incompatibleVersions) {
//running product version can be null if the property is not in deployment properties
if (null != runningProductVersion && Arrays.asList(incompatibleVersions).contains(runningProductVersion)) {
String errorMessage =
"Skipping test: " + this.getClass().getName() + " due to version mismatch. Running "
+ "product version: " + runningProductVersion + ", Non allowed versions: "
+ Arrays.toString(incompatibleVersions);
log.warn(errorMessage);
throw new SkipException(errorMessage);
}
}
/**
* Skip test if the test is executed in standalone mode since some tests need to be executed in distributed
* infrastructure. For example some tests required to assert log entries from ELK stack
*/
protected void skipTestsIfStandaloneDeployment() {
if (Boolean.valueOf(getInfrastructureProperty(ScenarioConstants.STANDALONE_DEPLOYMENT))) {
String errorMessage =
"Skipping test: " + this.getClass().getName() + " since this test require distributed deployment";
log.warn(errorMessage);
throw new SkipException(errorMessage);
}
}
@Override
public void testAggregation()
{
assertThatThrownBy(super::testAggregation)
.hasRootCauseMessage("line 1:26: Table 'druid.druid.nation' does not exist");
// TODO (https://github.com/prestosql/presto/issues/4116)
throw new SkipException("TODO");
}
@Test
@Override
// nation, region, customer tables don't have any date/time in the rows.
// For a table to be ingested into Druid, a date/time/timestamp column is required.
//TODO: This test needs to be adjusted to possibly join between lineitems and orders datasources
public void testJoin()
{
assertThatThrownBy(super::testJoin)
.hasRootCauseMessage("line 1:36: Table 'druid.druid.nation' does not exist");
// TODO (https://github.com/prestosql/presto/issues/4116)
throw new SkipException("TODO");
}
@Requires(TextRequirements.class)
@Test(groups = {HIVE_COERCION, JDBC})
public void testHiveCoercionTextFile()
{
if (getHiveVersionMajor() >= 3) {
throw new SkipException("Hive 3 forbids certain coercions, we should still test remaining"); // TODO (https://github.com/prestosql/presto/issues/1218)
}
doTestHiveCoercion(HIVE_COERCION_TEXTFILE);
}
@Requires(RcTextRequirements.class)
@Test(groups = {HIVE_COERCION, JDBC})
public void testHiveCoercionRcText()
{
if (getHiveVersionMajor() >= 3) {
throw new SkipException("Hive 3 forbids certain coercions, we should still test remaining"); // TODO (https://github.com/prestosql/presto/issues/1218)
}
doTestHiveCoercion(HIVE_COERCION_RCTEXT);
}
@Requires(RcBinaryRequirements.class)
@Test(groups = {HIVE_COERCION, JDBC})
public void testHiveCoercionRcBinary()
{
if (getHiveVersionMajor() >= 3) {
throw new SkipException("Hive 3 forbids certain coercions, we should still test remaining"); // TODO (https://github.com/prestosql/presto/issues/1218)
}
doTestHiveCoercion(HIVE_COERCION_RCBINARY);
}
@Requires(ParquetRequirements.class)
@Test(groups = {HIVE_COERCION, JDBC})
public void testHiveCoercionParquet()
{
if (getHiveVersionMajor() >= 3) {
throw new SkipException("Hive 3 forbids certain coercions, we should still test remaining"); // TODO (https://github.com/prestosql/presto/issues/1218)
}
doTestHiveCoercion(HIVE_COERCION_PARQUET);
}
@Test(groups = {ROLES, AUTHORIZATION, PROFILE_SPECIFIC_TESTS})
public void testListGrants()
{
if (getHiveVersionMajor() >= 3) {
throw new SkipException(""); // TODO (https://github.com/prestosql/presto/issues/1218) this currently fails on HDP 3
}
onPresto().executeQuery("SHOW GRANTS"); // must not fail
onPresto().executeQuery("SELECT * FROM information_schema.table_privileges"); // must not fail
onPresto().executeQuery("CREATE TABLE test_list_grants(c int)");
QueryAssert.assertThat(onPresto().executeQuery("SHOW GRANTS"))
.contains(
row(userName, "USER", userName, "USER", "hive", "default", "test_list_grants", "SELECT", "YES", null),
row(userName, "USER", userName, "USER", "hive", "default", "test_list_grants", "INSERT", "YES", null),
row(userName, "USER", userName, "USER", "hive", "default", "test_list_grants", "UPDATE", "YES", null),
row(userName, "USER", userName, "USER", "hive", "default", "test_list_grants", "DELETE", "YES", null));
QueryAssert.assertThat(onPresto().executeQuery("SELECT * FROM information_schema.table_privileges"))
.contains(
row(userName, "USER", userName, "USER", "hive", "default", "test_list_grants", "SELECT", "YES", null),
row(userName, "USER", userName, "USER", "hive", "default", "test_list_grants", "INSERT", "YES", null),
row(userName, "USER", userName, "USER", "hive", "default", "test_list_grants", "UPDATE", "YES", null),
row(userName, "USER", userName, "USER", "hive", "default", "test_list_grants", "DELETE", "YES", null));
onPresto().executeQuery("DROP TABLE test_list_grants");
}
@Test
public void testModernAvroValidatesNamespaces() throws Exception {
AvroVersion runtimeVersion = AvroCompatibilityHelper.getRuntimeAvroVersion();
if (!runtimeVersion.laterThan(AvroVersion.AVRO_1_4)) {
throw new SkipException("only supported under modern avro. runtime version detected as " + runtimeVersion);
}
String withAvsc = TestUtil.load("HasNamespace.avsc");
Schema with = Schema.parse(withAvsc);
String withoutAvsc = TestUtil.load("HasNoNamespace.avsc");
Schema without = Schema.parse(withoutAvsc);
GenericData.Record record = new GenericData.Record(without);
record.put("f", AvroCompatibilityHelper.newEnumSymbol(without.getField("f").schema(), "B"));
ByteArrayOutputStream os = new ByteArrayOutputStream();
GenericDatumWriter writer = new GenericDatumWriter(without);
BinaryEncoder encoder = AvroCompatibilityHelper.newBinaryEncoder(os);
//noinspection unchecked
writer.write(record, encoder);
encoder.flush();
byte[] bytes = os.toByteArray();
GenericDatumReader<GenericData.Record> reader = new GenericDatumReader<>(without, with);
BinaryDecoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
try {
GenericData.Record read = reader.read(null, decoder);
Assert.fail("deserialization was expected to fail");
} catch (Exception expected) {
Assert.assertTrue(expected.getMessage().contains("Found EnumType, expecting com.acme.EnumType"));
}
}
@Override
public void testGetPartitionSplitsTableOfflinePartition()
{
if (getHiveVersionMajor() >= 2) {
throw new SkipException("ALTER TABLE .. ENABLE OFFLINE was removed in Hive 2.0 and this is a prerequisite for this test");
}
super.testGetPartitionSplitsTableOfflinePartition();
}
@Override
public void testGetPartitionSplitsTableOfflinePartition()
{
if (getHiveVersionMajor() >= 2) {
throw new SkipException("ALTER TABLE .. ENABLE OFFLINE was removed in Hive 2.0 and this is a prerequisite for this test");
}
super.testGetPartitionSplitsTableOfflinePartition();
}
@Override
@Test(dataProvider = "testColumnNameDataProvider")
public void testColumnName(String columnName)
{
if (columnName.equals("a.dot")) {
// TODO (https://github.com/prestosql/presto/issues/3460)
assertThatThrownBy(() -> super.testColumnName(columnName))
.hasStackTraceContaining("TableWriterOperator") // during INSERT
.hasMessage("Invalid BSON field name a.dot");
throw new SkipException("Insert would fail");
}
super.testColumnName(columnName);
}
@Test
public void testAvro14DoesntValidateNamespace() throws Exception {
AvroVersion runtimeVersion = AvroCompatibilityHelper.getRuntimeAvroVersion();
if (runtimeVersion != AvroVersion.AVRO_1_4) {
throw new SkipException("only supported under " + AvroVersion.AVRO_1_4 + ". runtime version detected as " + runtimeVersion);
}
String withAvsc = TestUtil.load("HasNamespace.avsc");
Schema with = Schema.parse(withAvsc);
String withoutAvsc = TestUtil.load("HasNoNamespace.avsc");
Schema without = Schema.parse(withoutAvsc);
GenericData.Record record = new GenericData.Record(without);
record.put("f", AvroCompatibilityHelper.newEnumSymbol(without.getField("f").schema(), "B"));
ByteArrayOutputStream os = new ByteArrayOutputStream();
GenericDatumWriter writer = new GenericDatumWriter(without);
BinaryEncoder encoder = AvroCompatibilityHelper.newBinaryEncoder(os);
//noinspection unchecked
writer.write(record, encoder);
encoder.flush();
byte[] bytes = os.toByteArray();
GenericDatumReader<GenericData.Record> reader = new GenericDatumReader<>(without, with);
BinaryDecoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
GenericData.Record read = reader.read(null, decoder);
String value = String.valueOf(read.get("f"));
Assert.assertEquals(value, "B");
}
@Override
protected ConnectorTableHandle getTableHandle(ConnectorMetadata metadata, SchemaTableName tableName)
{
if (tableName.getTableName().startsWith(TEMPORARY_TABLE_PREFIX)) {
return super.getTableHandle(metadata, tableName);
}
throw new SkipException("tests using existing tables are not supported");
}
@Test
public void testCreateWithStagingDirectorySymlink()
throws Exception
{
java.nio.file.Path staging = createTempDirectory("staging");
java.nio.file.Path link = Paths.get(staging + ".symlink");
// staging = /tmp/stagingXXX
// link = /tmp/stagingXXX.symlink -> /tmp/stagingXXX
try {
try {
Files.createSymbolicLink(link, staging);
}
catch (UnsupportedOperationException e) {
throw new SkipException("Filesystem does not support symlinks", e);
}
try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
MockAmazonS3 s3 = new MockAmazonS3();
Configuration conf = new Configuration(false);
conf.set(S3_STAGING_DIRECTORY, link.toString());
fs.initialize(new URI("s3n://test-bucket/"), conf);
fs.setS3Client(s3);
FSDataOutputStream stream = fs.create(new Path("s3n://test-bucket/test"));
stream.close();
assertTrue(Files.exists(link));
}
}
finally {
deleteRecursively(link, ALLOW_INSECURE);
deleteRecursively(staging, ALLOW_INSECURE);
}
}
@BeforeClass
public void setup() throws IOException {
if (System.getProperty("os.name").startsWith("Win")) {
throw new SkipException("MiniDFSCluster doesn't wupport windows.");
}
System.setProperty("DJL_CACHE_DIR", "build/cache");
String userHome = System.getProperty("user.home");
System.setProperty("ENGINE_CACHE_DIR", userHome);
java.nio.file.Path dir = Paths.get("build/test/mlp");
java.nio.file.Path zipFile = Paths.get("build/test/mlp.zip");
java.nio.file.Path symbolFile = dir.resolve("mlp-symbol.json");
java.nio.file.Path paramFile = dir.resolve("mlp-0000.param");
Files.createDirectories(dir);
if (Files.notExists(symbolFile)) {
Files.createFile(symbolFile);
}
if (Files.notExists(paramFile)) {
Files.createFile(paramFile);
}
if (Files.notExists(zipFile)) {
ZipUtils.zip(dir, zipFile);
}
Configuration config = new Configuration();
setFilePermission(config);
miniDfs = new MiniDFSCluster(config, 1, true, null);
miniDfs.waitClusterUp();
FileSystem fs = miniDfs.getFileSystem();
fs.copyFromLocalFile(new Path(zipFile.toString()), new Path("/mlp.zip"));
fs.copyFromLocalFile(new Path(symbolFile.toString()), new Path("/mlp/mlp-symbol.json"));
fs.copyFromLocalFile(new Path(paramFile.toString()), new Path("/mlp/mlp-0000.param"));
}