Skip to content

Commit

Permalink
Add tests for S3 rename and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Apr 30, 2015
1 parent e0fe1c7 commit f1731ab
Showing 1 changed file with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package com.facebook.presto.hive;

import com.facebook.presto.hive.metastore.CachingHiveMetastore;
import com.facebook.presto.spi.ColumnMetadata;
import com.facebook.presto.spi.ColumnHandle;
import com.facebook.presto.spi.ColumnMetadata;
import com.facebook.presto.spi.ConnectorPageSource;
import com.facebook.presto.spi.ConnectorPageSourceProvider;
import com.facebook.presto.spi.ConnectorPartitionResult;
Expand Down Expand Up @@ -66,6 +66,7 @@
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService;
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
import static java.lang.String.format;
import static java.util.Locale.ENGLISH;
import static java.util.concurrent.Executors.newCachedThreadPool;
import static org.testng.Assert.assertEquals;
Expand All @@ -77,6 +78,8 @@ public abstract class AbstractTestHiveClientS3
{
private static final ConnectorSession SESSION = new ConnectorSession("user", UTC_KEY, ENGLISH, System.currentTimeMillis(), null);

protected String writableBucket;

protected String database;
protected SchemaTableName tableS3;
protected SchemaTableName temporaryCreateTable;
Expand Down Expand Up @@ -118,6 +121,8 @@ protected void setupHive(String databaseName)

protected void setup(String host, int port, String databaseName, String awsAccessKey, String awsSecretKey, String writableBucket)
{
this.writableBucket = writableBucket;

setupHive(databaseName);

HiveClientConfig hiveClientConfig = new HiveClientConfig()
Expand Down Expand Up @@ -196,6 +201,70 @@ public void testGetFileStatus()
assertFalse(fs.exists(new Path(basePath, "foo")));
}

@Test
public void testRename()
throws Exception
{
Path basePath = new Path(format("s3:https://%s/rename/%s/", writableBucket, UUID.randomUUID()));
FileSystem fs = hdfsEnvironment.getFileSystem(basePath);
assertFalse(fs.exists(basePath));

// create file foo.txt
Path path = new Path(basePath, "foo.txt");
assertTrue(fs.createNewFile(path));
assertTrue(fs.exists(path));

// rename foo.txt to bar.txt
Path newPath = new Path(basePath, "bar.txt");
assertFalse(fs.exists(newPath));
assertTrue(fs.rename(path, newPath));
assertFalse(fs.exists(path));
assertTrue(fs.exists(newPath));

// create file foo.txt and rename to bar.txt
assertTrue(fs.createNewFile(path));
assertFalse(fs.rename(path, newPath));
assertTrue(fs.exists(path));

// rename foo.txt to foo.txt
assertTrue(fs.rename(path, path));
assertTrue(fs.exists(path));

// delete foo.txt
assertTrue(fs.delete(path, false));
assertFalse(fs.exists(path));

// create directory source with file
Path source = new Path(basePath, "source");
assertTrue(fs.createNewFile(new Path(source, "test.txt")));

// rename source to non-existing target
Path target = new Path(basePath, "target");
assertFalse(fs.exists(target));
assertTrue(fs.rename(source, target));
assertFalse(fs.exists(source));
assertTrue(fs.exists(target));

// create directory source with file
assertTrue(fs.createNewFile(new Path(source, "test.txt")));

// rename source to existing target
assertTrue(fs.rename(source, target));
assertFalse(fs.exists(source));
target = new Path(target, "source");
assertTrue(fs.exists(target));
assertTrue(fs.exists(new Path(target, "test.txt")));

// delete target
target = new Path(basePath, "target");
assertTrue(fs.exists(target));
assertTrue(fs.delete(target, true));
assertFalse(fs.exists(target));

// cleanup
fs.delete(basePath, true);
}

@Test
public void testTableCreation()
throws Exception
Expand Down

0 comments on commit f1731ab

Please sign in to comment.