use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testUploadSingleFile.
@Test
public void testUploadSingleFile() throws Exception {
File tmpFile = tmpDir.newFile(TEMP_FILE_TMP_NAME);
Files.write(randomFileContents(), tmpFile);
// use standard client
IDataSpaceClient client = clientInstance();
LocalFileSource source = new LocalFileSource(tmpFile);
RemoteDestination dest = new RemoteDestination(USER, "testUploadSingleFile/" + TEMP_FILE_TMP_NAME);
assertTrue(client.upload(source, dest));
String destDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
File destFile = new File(destDirPath, "testUploadSingleFile/" + TEMP_FILE_TMP_NAME);
assertTrue(Files.equal(tmpFile, destFile));
// use RemoteSpace API
FileUtils.deleteQuietly(destFile);
client.getUserSpace().pushFile(tmpFile, "testUploadSingleFile/" + TEMP_FILE_TMP_NAME);
assertTrue(Files.equal(tmpFile, destFile));
}
use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testUploadSelectedFilesUsingFilenames.
@Test
public void testUploadSelectedFilesUsingFilenames() throws Exception {
TestFilesToUploadCreator testFiles = new TestFilesToUploadCreator().invoke();
File tempTextFile = testFiles.getTempTextFile();
File tempFile = testFiles.getTempFile();
// use standard client
IDataSpaceClient client = clientInstance();
LocalDirSource source = new LocalDirSource(tmpDir.getRoot());
source.setIncludes("**/" + TEMP_FILE_TMP_NAME);
RemoteDestination dest = new RemoteDestination(USER, "testUploadSelectedFilesUsingFilenames");
assertTrue(client.upload(source, dest));
String destRootUri = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
File[] destRootFiles = new File(destRootUri, "testUploadSelectedFilesUsingFilenames").listFiles();
assertEquals(1, destRootFiles.length);
assertTrue(Files.equal(tempFile, destRootFiles[0]));
// use RemoteSpace API
FileUtils.deleteDirectory(new File(destRootUri, "testUploadSelectedFilesUsingFilenames"));
client.getUserSpace().pushFiles(tmpDir.getRoot(), "**/" + TEMP_FILE_TMP_NAME, "testUploadSelectedFilesUsingFilenames");
destRootFiles = new File(destRootUri, "testUploadSelectedFilesUsingFilenames").listFiles();
assertEquals(1, destRootFiles.length);
assertTrue(Files.equal(tempFile, destRootFiles[0]));
}
use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testCreateFolder.
@Test
public void testCreateFolder() throws Exception {
URI srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0));
String folderName = "testcreatefolder";
RemoteSource source = new RemoteSource(USER, folderName);
source.setType(FileType.FOLDER);
IDataSpaceClient client = clientInstance();
assertTrue(client.create(source));
File expectedFile = new File(srcDirPath.getPath(), folderName);
assertTrue(expectedFile.exists());
assertTrue(expectedFile.isDirectory());
}
use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testDownloadArchiveFile.
private void testDownloadArchiveFile(String archiveFileName, URL archiveSource) throws Exception {
String srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
File srcFile = new File(srcDirPath, archiveFileName);
if (srcFile.exists()) {
assertTrue(srcFile.delete());
}
FileUtils.copyInputStreamToFile(archiveSource.openStream(), srcFile);
File tmpFile = tmpDir.newFile(archiveFileName);
if (tmpFile.exists()) {
assertTrue(tmpFile.delete());
}
// use standard client
IDataSpaceClient client = clientInstance();
RemoteSource source = new RemoteSource(USER, archiveFileName);
LocalDestination dest = new LocalDestination(tmpFile);
assertTrue(client.download(source, dest));
assertTrue(Files.equal(srcFile, tmpFile));
// use RemoteSpace API
FileUtils.deleteQuietly(tmpFile);
File downloadedFile = client.getUserSpace().pullFile(archiveFileName, tmpFile);
assertTrue(Files.equal(srcFile, downloadedFile));
}
use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testDownloadFile.
@Test
public void testDownloadFile() throws Exception {
String srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
File srcFile = new File(srcDirPath, TEMP_FILE_TMP_NAME);
if (srcFile.exists()) {
assertTrue(srcFile.delete());
}
Files.write(randomFileContents(), srcFile);
File tmpFile = tmpDir.newFile(TEMP_FILE_TMP_NAME);
if (tmpFile.exists()) {
assertTrue(tmpFile.delete());
}
// use standard client
IDataSpaceClient client = clientInstance();
RemoteSource source = new RemoteSource(USER, TEMP_FILE_TMP_NAME);
LocalDestination dest = new LocalDestination(tmpFile);
assertTrue(client.download(source, dest));
assertTrue(Files.equal(srcFile, tmpFile));
// use RemoteSpace API
FileUtils.deleteQuietly(tmpFile);
File downloadedFile = client.getUserSpace().pullFile(TEMP_FILE_TMP_NAME, tmpFile);
assertTrue(Files.equal(srcFile, downloadedFile));
}
Aggregations