diff --git a/datavault-common/src/main/java/org/datavaultplatform/test/TSMTest.java b/datavault-common/src/main/java/org/datavaultplatform/test/TSMTest.java new file mode 100644 index 000000000..5663be983 --- /dev/null +++ b/datavault-common/src/main/java/org/datavaultplatform/test/TSMTest.java @@ -0,0 +1,5 @@ +package org.datavaultplatform.test; + +public interface TSMTest { + /* category marker */ +} diff --git a/datavault-worker/pom.xml b/datavault-worker/pom.xml index c1c84b1ae..a7f944592 100644 --- a/datavault-worker/pom.xml +++ b/datavault-worker/pom.xml @@ -144,6 +144,8 @@ **/*Test.java + + org.datavaultplatform.test.TSMTest diff --git a/datavault-worker/src/test/java/org/datavaultplatform/common/storage/impl/TivoliStorageManagerTest.java b/datavault-worker/src/test/java/org/datavaultplatform/common/storage/impl/TivoliStorageManagerTest.java index 937a9256c..489f9a042 100644 --- a/datavault-worker/src/test/java/org/datavaultplatform/common/storage/impl/TivoliStorageManagerTest.java +++ b/datavault-worker/src/test/java/org/datavaultplatform/common/storage/impl/TivoliStorageManagerTest.java @@ -19,6 +19,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; public class TivoliStorageManagerTest { @@ -68,146 +69,151 @@ private void deleteArchive(String description, String optFilePath) throws Excep } @Test + @Category(org.datavaultplatform.test.TSMTest.class) public void testStoreValidParams() { -// Progress progress = new Progress(); -// File working = new File(tsmResources, "test.tar"); -// String path = "/tmp"; -// String retVal = null; -// try { -// // store the tar -// retVal = tsm.store(path, working, progress); -// assertNotNull("RetVal should not be null", retVal); -// // check it is now in TSM node 1 -// BufferedReader reader = this.queryArchive(working, retVal, TivoliStorageManager.TSM_SERVER_NODE1_OPT); -// String line = null; -// while ( (line = reader.readLine()) != null) { -// assertFalse("Node1 attempt to store failed", line.contains("No files matching search criteria were found")); -// } -// -// reader = this.queryArchive(working, retVal, TivoliStorageManager.TSM_SERVER_NODE2_OPT); -// line = null; -// while ( (line = reader.readLine()) != null) { -// assertFalse("Node2 attempt to store failed", line.contains("No files matching search criteria were found")); -// } -// -// // delete from TSM node 1 -// deleteArchive(retVal, TivoliStorageManager.TSM_SERVER_NODE1_OPT); -// deleteArchive(retVal, TivoliStorageManager.TSM_SERVER_NODE2_OPT); -// } catch (Exception e) { -// fail("Unexpected exception " + e.getMessage()); -// } + Progress progress = new Progress(); + File working = new File(tsmResources, "test.tar"); + String path = "/tmp"; + String retVal = null; + try { + // store the tar + retVal = tsm.store(path, working, progress); + assertNotNull("RetVal should not be null", retVal); + // check it is now in TSM node 1 + BufferedReader reader = this.queryArchive(working, retVal, TivoliStorageManager.TSM_SERVER_NODE1_OPT); + String line = null; + while ( (line = reader.readLine()) != null) { + assertFalse("Node1 attempt to store failed", line.contains("No files matching search criteria were found")); + } + + reader = this.queryArchive(working, retVal, TivoliStorageManager.TSM_SERVER_NODE2_OPT); + line = null; + while ( (line = reader.readLine()) != null) { + assertFalse("Node2 attempt to store failed", line.contains("No files matching search criteria were found")); + } + + // delete from TSM node 1 + deleteArchive(retVal, TivoliStorageManager.TSM_SERVER_NODE1_OPT); + deleteArchive(retVal, TivoliStorageManager.TSM_SERVER_NODE2_OPT); + } catch (Exception e) { + fail("Unexpected exception " + e.getMessage()); + } } @Test + @Category(org.datavaultplatform.test.TSMTest.class) public void testStoreNonExistantFile() { -// Progress progress = new Progress(); -// File working = new File(tsmResources, "testx.tar"); -// String path = "/tmp"; -// try { -// // store the tar -// tsm.store(path, working, progress); -// // exception should be thrown by store so we should never get here -// fail("Exception should have been thrown"); -// } catch (Exception e) { -// assertNotNull("Exception should not be null", e); -// assertEquals("Message not as expected", "Deposit of testx.tar using /opt/tivoli/tsm/client/ba/bin/dsm1.opt failed. ", e.getMessage()); -// } + Progress progress = new Progress(); + File working = new File(tsmResources, "testx.tar"); + String path = "/tmp"; + try { + // store the tar + tsm.store(path, working, progress); + // exception should be thrown by store so we should never get here + fail("Exception should have been thrown"); + } catch (Exception e) { + assertNotNull("Exception should not be null", e); + assertEquals("Message not as expected", "Deposit of testx.tar using /opt/tivoli/tsm/client/ba/bin/dsm1.opt failed. ", e.getMessage()); + } } @Test + @Category(org.datavaultplatform.test.TSMTest.class) public void testRetrieveValidParams() { -// Progress progress = new Progress(); -// File working = new File(tsmResources, "test.tar"); -// File temp = new File(tsmResources, "test.tar.tmp"); -// String path = "/tmp"; -// String retVal = null; -// try { -// // store the tar -// System.out.println("Store the tar"); -// retVal = tsm.store(path, working, progress); -// //File retrieved = new File("/tmp/" + retVal); -// assertNotNull("RetVal should not be null", retVal); -// // check it is now in TSM node 1 -// System.out.println("check it has been archived"); -// BufferedReader reader = this.queryArchive(working, retVal, TivoliStorageManager.TSM_SERVER_NODE1_OPT); -// String line = null; -// while ( (line = reader.readLine()) != null) { -// assertFalse("Node 1 attempt to store failed", line.contains("No files matching search criteria were found")); -// } -// -// reader = this.queryArchive(working, retVal, TivoliStorageManager.TSM_SERVER_NODE2_OPT); -// line = null; -// while ( (line = reader.readLine()) != null) { -// assertFalse("Node 2 attempt to store failed", line.contains("No files matching search criteria were found")); -// } -// -// // temp move the file (so we can retrieve without overwriting) -// FileUtils.moveFile(working, temp); -// assertFalse("The working file shouldn't exist", working.exists()); -// -// // retrieve from TSM node 1 -// System.out.println("Retrieve the tar"); -// //dsmc retrieve /tmp/datavault/temp/2848@ubuntu-xenial/513c2b11-30df-4947-846b-a64309c61eb8.tar -// tsm.retrieve(path, working, progress, TivoliStorageManager.TSM_SERVER_NODE1_OPT); -// -// // check that the /tmp/"retval" dir now exists -// System.out.println("Check the retrieve archive exits"); -// assertTrue("The retrieved archive doesn't exist", working.exists()); -// -// // delete from TSM node 1 -// System.out.println("Delete from TSM"); -// deleteArchive(retVal, TivoliStorageManager.TSM_SERVER_NODE1_OPT); -// -// // delete from TSM node2 -// deleteArchive(retVal, TivoliStorageManager.TSM_SERVER_NODE2_OPT); -// -// // delete the retrieved tar -// System.out.println("Delete the retrieved archive"); -// Boolean deleted = working.delete(); -// assertTrue("Retrieved archive not cleaned up", deleted); -// -// // move the source file back -// FileUtils.moveFile(temp, working); -// assertTrue("The working file should exist", working.exists()); -// } catch (Exception e) { -// fail("Unexpected exception " + e.getMessage()); -// } + Progress progress = new Progress(); + File working = new File(tsmResources, "test.tar"); + File temp = new File(tsmResources, "test.tar.tmp"); + String path = "/tmp"; + String retVal = null; + try { + // store the tar + System.out.println("Store the tar"); + retVal = tsm.store(path, working, progress); + //File retrieved = new File("/tmp/" + retVal); + assertNotNull("RetVal should not be null", retVal); + // check it is now in TSM node 1 + System.out.println("check it has been archived"); + BufferedReader reader = this.queryArchive(working, retVal, TivoliStorageManager.TSM_SERVER_NODE1_OPT); + String line = null; + while ( (line = reader.readLine()) != null) { + assertFalse("Node 1 attempt to store failed", line.contains("No files matching search criteria were found")); + } + + reader = this.queryArchive(working, retVal, TivoliStorageManager.TSM_SERVER_NODE2_OPT); + line = null; + while ( (line = reader.readLine()) != null) { + assertFalse("Node 2 attempt to store failed", line.contains("No files matching search criteria were found")); + } + + // temp move the file (so we can retrieve without overwriting) + FileUtils.moveFile(working, temp); + assertFalse("The working file shouldn't exist", working.exists()); + + // retrieve from TSM node 1 + System.out.println("Retrieve the tar"); + //dsmc retrieve /tmp/datavault/temp/2848@ubuntu-xenial/513c2b11-30df-4947-846b-a64309c61eb8.tar + tsm.retrieve(path, working, progress, TivoliStorageManager.TSM_SERVER_NODE1_OPT); + + // check that the /tmp/"retval" dir now exists + System.out.println("Check the retrieve archive exits"); + assertTrue("The retrieved archive doesn't exist", working.exists()); + + // delete from TSM node 1 + System.out.println("Delete from TSM"); + deleteArchive(retVal, TivoliStorageManager.TSM_SERVER_NODE1_OPT); + + // delete from TSM node2 + deleteArchive(retVal, TivoliStorageManager.TSM_SERVER_NODE2_OPT); + + // delete the retrieved tar + System.out.println("Delete the retrieved archive"); + Boolean deleted = working.delete(); + assertTrue("Retrieved archive not cleaned up", deleted); + + // move the source file back + FileUtils.moveFile(temp, working); + assertTrue("The working file should exist", working.exists()); + } catch (Exception e) { + fail("Unexpected exception " + e.getMessage()); + } } @Test + @Category(org.datavaultplatform.test.TSMTest.class) public void testRetrieveNonExistantFileFromNodeOne() { // retrieve from TSM -// Progress progress = new Progress(); -// File working = new File("/tmp/test.tar"); -// String path = "/tmp"; -// -// try { -// System.out.println("Retrieve the tar"); -// //dsmc retrieve /tmp/datavault/temp/2848@ubuntu-xenial/513c2b11-30df-4947-846b-a64309c61eb8.tar -// tsm.retrieve(path, working, progress, TivoliStorageManager.TSM_SERVER_NODE1_OPT); -// fail("Exception should have been thrown"); -// } catch (Exception e) { -// assertNotNull("Exception should not be null", e); -// assertEquals("Message not as expected", "Retrieval of test.tar failed. ", e.getMessage()); -// } + Progress progress = new Progress(); + File working = new File("/tmp/test.tar"); + String path = "/tmp"; + + try { + System.out.println("Retrieve the tar"); + //dsmc retrieve /tmp/datavault/temp/2848@ubuntu-xenial/513c2b11-30df-4947-846b-a64309c61eb8.tar + tsm.retrieve(path, working, progress, TivoliStorageManager.TSM_SERVER_NODE1_OPT); + fail("Exception should have been thrown"); + } catch (Exception e) { + assertNotNull("Exception should not be null", e); + assertEquals("Message not as expected", "Retrieval of test.tar failed. ", e.getMessage()); + } } @Test + @Category(org.datavaultplatform.test.TSMTest.class) public void testRetrieveNonExistantFileFromNodeTwo() { // retrieve from TSM -// Progress progress = new Progress(); -// File working = new File("/tmp/test.tar"); -// String path = "/tmp"; -// -// try { -// System.out.println("Retrieve the tar"); -// //dsmc retrieve /tmp/datavault/temp/2848@ubuntu-xenial/513c2b11-30df-4947-846b-a64309c61eb8.tar -// tsm.retrieve(path, working, progress, TivoliStorageManager.TSM_SERVER_NODE2_OPT); -// fail("Exception should have been thrown"); -// } catch (Exception e) { -// assertNotNull("Exception should not be null", e); -// assertEquals("Message not as expected", "Retrieval of test.tar failed. ", e.getMessage()); -// } + Progress progress = new Progress(); + File working = new File("/tmp/test.tar"); + String path = "/tmp"; + + try { + System.out.println("Retrieve the tar"); + //dsmc retrieve /tmp/datavault/temp/2848@ubuntu-xenial/513c2b11-30df-4947-846b-a64309c61eb8.tar + tsm.retrieve(path, working, progress, TivoliStorageManager.TSM_SERVER_NODE2_OPT); + fail("Exception should have been thrown"); + } catch (Exception e) { + assertNotNull("Exception should not be null", e); + assertEquals("Message not as expected", "Retrieval of test.tar failed. ", e.getMessage()); + } } @After