Search in sources :

Example 6 with JaqyInterpreter

use of com.teradata.jaqy.JaqyInterpreter in project jaqy by Teradata.

the class S3PathTest method test1.

@Test
public void test1() throws Exception {
    /*
		 * A workaround for S3Mock generating an output to stdout.
		 *     https://github.com/findify/s3mock/issues/67
		 * It generates an output in Eclipse, but not so when running
		 * mvn clean test.
		 */
    InMemoryProvider provider = new InMemoryProvider();
    ActorSystem actor = S3Mock.$lessinit$greater$default$3(8001, provider);
    S3Mock api = new S3Mock(8001, provider, actor);
    api.start();
    // setup
    Globals globals = new Globals();
    JaqyInterpreter interpreter = new JaqyInterpreter(globals, null, null);
    AmazonS3ClientBuilder builder = S3Utils.getS3Builder(interpreter);
    builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8001", "us-west-2"));
    // setup some files in the bucket
    AmazonS3 s3client = builder.build();
    s3client.createBucket("tests");
    File dir = new File("../tests/unittests/csv/lib");
    s3client.putObject("tests", "unittests/csv/lib/sin.csv", new File(dir, "sin.csv"));
    s3client.putObject("tests", "unittests/csv/lib/sin2.csv", new File(dir, "sin2.csv"));
    s3client.shutdown();
    S3PathHandler handler = new S3PathHandler();
    String url = "s3://tests/unittests/csv/lib/sin.csv";
    String parent = "s3://tests/unittests/csv/lib";
    S3Path path = (S3Path) handler.getPath(url, interpreter);
    Assert.assertNotNull(path);
    Assert.assertEquals("tests", path.getBucket());
    Assert.assertEquals("unittests/csv/lib/sin.csv", path.getFile());
    Assert.assertEquals(url, path.getPath());
    Assert.assertEquals(url, path.getCanonicalPath());
    Assert.assertTrue(path.exists());
    Assert.assertEquals(31443, path.length());
    Assert.assertEquals(31443, path.length());
    Assert.assertTrue(path.isFile());
    Assert.assertEquals(0, FileUtils.compare(path.getInputStream(), new FileInputStream(new File(dir, "sin.csv"))));
    path = (S3Path) path.getParent();
    Assert.assertEquals(parent, path.getPath());
    path = (S3Path) path.getRelativePath("sin2.csv");
    Assert.assertEquals("s3://tests/unittests/csv/lib/sin2.csv", path.getPath());
    Assert.assertTrue(path.isFile());
    path = (S3Path) path.getParent();
    path = (S3Path) path.getRelativePath("/unittests/csv/lib/import1.csv");
    Assert.assertEquals("s3://tests/unittests/csv/lib/import1.csv", path.getPath());
    FileUtils.copy(path.getOutputStream(), new FileInputStream(new File(dir, "import1.csv")), new byte[4096]);
    Assert.assertEquals(25, path.length());
    Assert.assertEquals(25, path.length());
    Assert.assertEquals(0, FileUtils.compare(path.getInputStream(), new FileInputStream(new File(dir, "import1.csv"))));
    path = (S3Path) path.getParent();
    path = (S3Path) path.getRelativePath("../../csv/lib/sin.csv");
    Assert.assertEquals(url, path.getPath());
    path = (S3Path) path.getParent();
    path = (S3Path) path.getRelativePath("../test/abc.csv");
    Assert.assertEquals(0, path.length());
    Assert.assertEquals(0, path.length());
    Assert.assertFalse(path.exists());
    Assert.assertFalse(path.exists());
    s3client = S3Utils.getS3Client(interpreter);
    if (s3client != null)
        s3client.shutdown();
    CoordinatedShutdown.get(actor).runAll();
    api.stop();
}
Also used : ActorSystem(akka.actor.ActorSystem) Globals(com.teradata.jaqy.Globals) AmazonS3(com.amazonaws.services.s3.AmazonS3) JaqyInterpreter(com.teradata.jaqy.JaqyInterpreter) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) InMemoryProvider(io.findify.s3mock.provider.InMemoryProvider) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) FileInputStream(java.io.FileInputStream) File(java.io.File) S3Mock(io.findify.s3mock.S3Mock) Test(org.junit.Test)

Aggregations

Globals (com.teradata.jaqy.Globals)6 JaqyInterpreter (com.teradata.jaqy.JaqyInterpreter)6 Test (org.junit.Test)6 VariableManager (com.teradata.jaqy.VariableManager)4 ExpNode (com.teradata.jaqy.utils.exp.ExpNode)4 ActorSystem (akka.actor.ActorSystem)1 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)1 S3Mock (io.findify.s3mock.S3Mock)1 InMemoryProvider (io.findify.s3mock.provider.InMemoryProvider)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1