org.testng.SkipException Java Examples

The following examples show how to use org.testng.SkipException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestHiveDistributedQueries.java    From presto with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: ZipFSPermissionsTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #3
Source File: Avro14FactoryCompatibilityTest.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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
}
 
Example #4
Source File: Avro14FactoryCompatibilityTest.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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$
  }
}
 
Example #5
Source File: AvroCompatibilityHelperTest.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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"));
}
 
Example #6
Source File: TestHiveTransactionalTable.java    From presto with Apache License 2.0 6 votes vote down vote up
@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");
    }
}
 
Example #7
Source File: AvroCompatibilityHelperTest.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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"));
}
 
Example #8
Source File: FHIRPathPatchSpecTest.java    From FHIR with Apache License 2.0 6 votes vote down vote up
@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");
    }
}
 
Example #9
Source File: TrainResNetTest.java    From djl with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #10
Source File: TrainResNetTest.java    From djl with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #11
Source File: NDArrayCreationOpTest.java    From djl with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #12
Source File: ResnetTest.java    From djl with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #13
Source File: SingleShotDetectionTest.java    From djl with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #14
Source File: Avro17FactoryTest.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testParseBadDefaultsSucceedsOn17() throws Exception {
  AvroVersion runtimeVersion = AvroCompatibilityHelper.getRuntimeAvroVersion();
  if (runtimeVersion != AvroVersion.AVRO_1_7) {
    throw new SkipException("only supported under " + AvroVersion.AVRO_1_7 + ". runtime version detected as " + runtimeVersion);
  }
  _factory.parse(BAD_DEFAULTS_SCHEMA_JSON, null); //expected to succeed
}
 
Example #15
Source File: SmartMulticastProcessorTest.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Override
public void required_createPublisher3MustProduceAStreamOfExactly3Elements() {
	try {
		super.required_createPublisher3MustProduceAStreamOfExactly3Elements();
	}
	catch (Throwable t) {
		throw new SkipException("Ignored due to undetermined drop-on-overflow behavior for that processor");
	}
}
 
Example #16
Source File: SmartMulticastProcessorTest.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Override
public void required_spec317_mustSupportAPendingElementCountUpToLongMaxValue() {
	try {
		super.required_spec317_mustSupportAPendingElementCountUpToLongMaxValue();
	}
	catch (Throwable t) {
		throw new SkipException("Ignored due to undetermined drop-on-overflow behavior for that processor");
	}
}
 
Example #17
Source File: SmartMulticastProcessorTest.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Override
public void required_spec317_mustSupportACumulativePendingElementCountUpToLongMaxValue() {
	try {
		super.required_spec317_mustSupportACumulativePendingElementCountUpToLongMaxValue();
	}
	catch (Throwable t) {
		throw new SkipException("Ignored due to undetermined drop-on-overflow behavior for that processor");
	}
}
 
Example #18
Source File: Avro17FactoryTest.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@BeforeClass
public void skipForOldAvro() throws Exception {
  AvroVersion runtimeVersion = AvroCompatibilityHelper.getRuntimeAvroVersion();
  List<AvroVersion> supportedVersions = Arrays.asList(AvroVersion.AVRO_1_7, AvroVersion.AVRO_1_8);
  if (!supportedVersions.contains(runtimeVersion)) {
    throw new SkipException("class only supported under " + supportedVersions + ". runtime version detected as " + runtimeVersion);
  }
  _factory = new Avro17Adapter();
}
 
Example #19
Source File: Avro17FactoryTest.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test(expectedExceptions = AvroTypeException.class)
public void testParseBadDefaultsFailsOn18() throws Exception {
  AvroVersion runtimeVersion = AvroCompatibilityHelper.getRuntimeAvroVersion();
  if (runtimeVersion != AvroVersion.AVRO_1_8) {
    throw new SkipException("only supported under " + AvroVersion.AVRO_1_8 + ". runtime version detected as " + runtimeVersion);
  }
  _factory.parse(BAD_DEFAULTS_SCHEMA_JSON, null);
}
 
Example #20
Source File: LegacyAvroSchemaTest.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testFixMalformedSchema() throws Exception {
  if (!AvroCompatibilityHelper.getRuntimeAvroVersion().laterThan(AvroVersion.AVRO_1_4)) {
    throw new SkipException("test only valid under modern avro");
  }
  String id = "123";
  LegacyAvroSchema legacyAvroSchema = new LegacyAvroSchema(id, badSchemaJson);
  Assert.assertNotNull(legacyAvroSchema);
  Assert.assertEquals(id, legacyAvroSchema.getOriginalSchemaId());
  JSONAssert.assertEquals("minified json should be equal to input", badSchemaJson, legacyAvroSchema.getOriginalSchemaJson(), true);
}
 
Example #21
Source File: LegacyAvroSchemaTest.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testMalformedSchemaWorks() throws Exception {
  if (AvroCompatibilityHelper.getRuntimeAvroVersion() != AvroVersion.AVRO_1_4) {
    throw new SkipException("test only valid under avro 1.4");
  }
  String id = "123";
  LegacyAvroSchema legacyAvroSchema = new LegacyAvroSchema(id, badSchemaJson);
  Assert.assertNotNull(legacyAvroSchema);
  Assert.assertEquals(id, legacyAvroSchema.getOriginalSchemaId());
  JSONAssert.assertEquals("minified json should be equal to input", badSchemaJson, legacyAvroSchema.getOriginalSchemaJson(), true);
  Assert.assertEquals(Schema.parse(badSchemaJson), legacyAvroSchema.getFixedSchema());
  Assert.assertNull(legacyAvroSchema.getIssue()); //nothing wrong with it
  Assert.assertTrue(legacyAvroSchema.getTransforms().isEmpty());
}
 
Example #22
Source File: NDImageUtilsTest.java    From djl with Apache License 2.0 5 votes vote down vote up
@Test
public void testToTensor() {
    if (Engine.getInstance().getEngineName().equals("TensorFlow")) {
        throw new SkipException("TensorFlow use channels last by default.");
    }
    try (NDManager manager = NDManager.newBaseManager()) {
        // test 3D C, H, W
        NDArray image = manager.randomUniform(0, 255, new Shape(4, 2, 3));
        NDArray toTensor = NDImageUtils.toTensor(image);
        NDArray expected = image.div(255f).transpose(2, 0, 1);
        Assertions.assertAlmostEquals(toTensor, expected);

        // test 4D N, C, H, W
        NDArray batchImages = manager.randomUniform(0, 255, new Shape(5, 3, 4, 2));
        toTensor = NDImageUtils.toTensor(batchImages);
        expected = batchImages.div(255f).transpose(0, 3, 1, 2);
        Assertions.assertAlmostEquals(toTensor, expected);

        // test zero-dim
        image = manager.create(new Shape(0, 1, 3));
        toTensor = NDImageUtils.toTensor(image);
        expected = manager.create(new Shape(3, 0, 1));
        Assert.assertEquals(toTensor, expected);
        batchImages = manager.create(new Shape(4, 0, 1, 3));
        toTensor = NDImageUtils.toTensor(batchImages);
        expected = manager.create(new Shape(4, 3, 0, 1));
        Assert.assertEquals(toTensor, expected);
    }
}
 
Example #23
Source File: NDImageUtilsTest.java    From djl with Apache License 2.0 5 votes vote down vote up
@Test
public void testNormalize() {
    if (Engine.getInstance().getEngineName().equals("TensorFlow")) {
        throw new SkipException("TensorFlow use channels last by default.");
    }
    try (NDManager manager = NDManager.newBaseManager()) {
        // test 3D C, H, W
        NDArray image = manager.ones(new Shape(3, 4, 2));
        float[] mean = {0.3f, 0.4f, 0.5f};
        float[] std = {0.8f, 0.8f, 0.8f};
        NDArray normalized = NDImageUtils.normalize(image, mean, std);
        NDArray expected = manager.create(new Shape(3, 4, 2));
        expected.set(new NDIndex("0,:,:"), 0.875);
        expected.set(new NDIndex("1,:,:"), 0.75f);
        expected.set(new NDIndex("2,:,:"), 0.625f);
        Assertions.assertAlmostEquals(normalized, expected);

        // test 4D N, C, H, W
        NDArray batchImages = manager.ones(new Shape(5, 3, 4, 2));
        mean = new float[] {0.6f, 0.7f, 0.8f};
        std = new float[] {0.1f, 0.2f, 0.3f};
        normalized = NDImageUtils.normalize(batchImages, mean, std);
        expected = manager.create(new Shape(5, 3, 4, 2));
        expected.set(new NDIndex(":,0,:,:"), 3.999999f);
        expected.set(new NDIndex(":,1,:,:"), 1.5);
        expected.set(new NDIndex(":,2,:,:"), 0.666666f);
        Assertions.assertAlmostEquals(normalized, expected);

        // test zero-dim
        image = manager.create(new Shape(3, 0, 1));
        normalized = NDImageUtils.normalize(image, mean, std);
        Assert.assertEquals(normalized, image);
        batchImages = manager.create(new Shape(4, 3, 0, 1));
        normalized = NDImageUtils.normalize(batchImages, mean, std);
        Assert.assertEquals(normalized, batchImages);
    }
}
 
Example #24
Source File: LegacyAvroSchemaTest.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testFixInvalidDefaultValues() throws Exception {
  if (!AvroCompatibilityHelper.getRuntimeAvroVersion().laterThan(AvroVersion.AVRO_1_7)) {
    throw new SkipException("test only valid under avro 1.8+");
  }
  String id = "123";
  LegacyAvroSchema legacyAvroSchema = new LegacyAvroSchema(id, badSchemaJson);
  Assert.assertNotNull(legacyAvroSchema.getIssue());
  Assert.assertNotNull(legacyAvroSchema.getFixedSchema());
}
 
Example #25
Source File: MonsantoSchemaTest.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test(expectedExceptions = SchemaParseException.class)
public void demonstrateBadSchema() 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 originalAvsc = TestUtil.load("BadInnerNamespace.avsc");
  Schema parsed = Schema.parse(originalAvsc);
  String toStringOutput = parsed.toString();
  Schema.parse(toStringOutput);
  Assert.fail("2nd parse expected to throw");
}
 
Example #26
Source File: IntegrationTest.java    From djl with Apache License 2.0 5 votes vote down vote up
public TestResult runTest(int index) {
    if (!beforeTest()) {
        return TestResult.FAILED;
    }

    TestResult result;
    Method method = testMethods.get(index);
    try {
        method.invoke(object);
        logger.info("Test {}.{} PASSED", getName(), method.getName());
        result = TestResult.SUCCESS;
    } catch (IllegalAccessException | InvocationTargetException e) {
        if (expectedException(method, e)) {
            logger.info("Test {}.{} PASSED", getName(), method.getName());
            result = TestResult.SUCCESS;
        } else if (e.getCause() instanceof SkipException) {
            logger.info("Test {}.{} SKIPPED", getName(), method.getName());
            result = TestResult.SKIPPED;
        } else if (e.getCause() instanceof UnsupportedOperationException) {
            logger.info("Test {}.{} UNSUPPORTED", getName(), method.getName());
            logger.debug("", e.getCause());
            result = TestResult.UNSUPPORTED;
        } else {
            logger.error("Test {}.{} FAILED", getName(), method.getName());
            logger.error("", e.getCause());
            result = TestResult.FAILED;
        }
    } finally {
        afterTest();
    }
    return result;
}
 
Example #27
Source File: TestPrestoS3FileSystem.java    From presto with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #28
Source File: HdfsRepositoryTest.java    From djl with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example #29
Source File: ScenarioTestBase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #30
Source File: TrainCookingStackExchange.java    From djl with Apache License 2.0 5 votes vote down vote up
@Test(enabled = false)
public void testBlazingText() throws IOException, ModelException, TranslateException {
    if (!Boolean.getBoolean("nightly")) {
        throw new SkipException("Nightly only");
    }

    URL url =
            new URL(
                    "https://djl-ai.s3.amazonaws.com/resources/test-models/blazingtext_classification.bin");
    Path path = Paths.get("build/tmp/model");
    Path modelFile = path.resolve("text_classification.bin");
    if (!Files.exists(modelFile)) {
        Files.createDirectories(path);
        try (InputStream is = url.openStream()) {
            Files.copy(is, modelFile);
        }
    }

    TextClassificationTranslator translator = new TextClassificationTranslator();
    try (Model model = Model.newInstance("text_classification")) {
        model.load(path);
        try (Predictor<String, Classifications> predictor = model.newPredictor(translator)) {
            Classifications result =
                    predictor.predict(
                            "Convair was an american aircraft manufacturing company which later expanded into rockets and spacecraft .");

            logger.info("{}", result);
            Assert.assertEquals(result.item(0).getClassName(), "Company");
        }
    }
}