Search in sources :

Example 1 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class MultiTenantShareMapper method createTenantShare.

/**
 * Create a tenant domain specific share
 */
private final DiskSharedDevice createTenantShare(String tenantDomain) {
    logger.debug("create tenant share for domain " + tenantDomain);
    StoreRef storeRef = new StoreRef(getStoreName());
    NodeRef rootNodeRef = new NodeRef(storeRef.getProtocol(), storeRef.getIdentifier(), "dummy");
    // Root nodeRef is required for storeRef part
    rootNodeRef = m_alfrescoConfig.getTenantService().getRootNode(m_alfrescoConfig.getNodeService(), m_alfrescoConfig.getSearchService(), m_alfrescoConfig.getNamespaceService(), getRootPath(), rootNodeRef);
    // Create the disk driver and context
    DiskInterface diskDrv = getRepoDiskInterface();
    ContentContext diskCtx = new ContentContext(m_tenantShareName, getStoreName(), getRootPath(), rootNodeRef);
    if (m_quotaManager != null) {
        diskCtx.setQuotaManager(m_quotaManager);
    }
    if (m_config instanceof ServerConfigurationBean) {
        ServerConfigurationBean config = (ServerConfigurationBean) m_config;
        config.initialiseRuntimeContext("cifs.tenant." + tenantDomain, diskCtx);
    } else {
        throw new AlfrescoRuntimeException("configuration error, unknown configuration bean");
    }
    // Default the filesystem to look like an 80Gb sized disk with 90% free space
    diskCtx.setDiskInformation(new SrvDiskInfo(2560, 64, 512, 2304));
    return new DiskSharedDevice(m_tenantShareName, diskDrv, diskCtx);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SrvDiskInfo(org.alfresco.jlan.server.filesys.SrvDiskInfo) ServerConfigurationBean(org.alfresco.filesys.config.ServerConfigurationBean) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DiskInterface(org.alfresco.jlan.server.filesys.DiskInterface) ContentContext(org.alfresco.filesys.repo.ContentContext) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 2 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testGedit.

// testScenarioMacMountainLionKeynote_MNT_8558
/**
 *  Gedit has the nasty behaviour of renaming an open file.
 *  1) create file (gedit12345678.txt)
 *  2) create temp file (.goutputStream-IRYDPW) write and flush
 *  3) rename (fails name collision)
 *  4) delete target
 *  5) rename this one succeeds
 *  6) close temp file
 */
public void testGedit() throws Exception {
    logger.debug("testGEdit");
    final String FILE_NAME = "gedit12345678.txt";
    final String FILE_TITLE = "Gedit";
    final String FILE_DESCRIPTION = "This is a test document to test CIFS shuffle";
    final String TEMP_FILE_NAME = ".goutputStream-IRYDPW";
    final String UPDATE_TEXT = "Shuffle an open file";
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile tempFileHandle;

        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testGEdit";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Clean up from a previous run
     */
    RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    /**
     * Create a file in the test directory
     */
    RetryingTransactionCallback<Void> createTestFileFirstTime = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            /**
             * Create the file we are going to use
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_TITLE, FILE_TITLE);
            nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_DESCRIPTION, FILE_DESCRIPTION);
            String testContent = "Gedit shuffle test";
            byte[] testContentBytes = testContent.getBytes();
            testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createTestFileFirstTime, false, true);
    /**
     * Create the temp file
     * add content
     * leave open
     */
    RetryingTransactionCallback<Void> createTempFile = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams params = new FileOpenParams(TEST_DIR + "\\" + TEMP_FILE_NAME, FileAction.TruncateExisting, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            NetworkFile file = driver.createFile(testSession, testConnection, params);
            testContext.tempFileHandle = file;
            String testContent = UPDATE_TEXT;
            byte[] testContentBytes = testContent.getBytes();
            testContext.tempFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            return null;
        }
    };
    tran.doInTransaction(createTempFile, false, true);
    /**
     * rename the test file to the temp
     */
    RetryingTransactionCallback<Void> renameTestFileToTemp = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + TEMP_FILE_NAME, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    // expect this one to fail
    try {
        tran.doInTransaction(renameTestFileToTemp, false, true);
        fail("should have failed");
    } catch (Exception e) {
    // expect to go here
    }
    /**
     * delete the target file
     */
    RetryingTransactionCallback<Void> deleteTargetFile = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(deleteTargetFile, false, true);
    // This one should succeed
    tran.doInTransaction(renameTestFileToTemp, false, true);
    RetryingTransactionCallback<Void> closeTempFile = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
            return null;
        }
    };
    tran.doInTransaction(closeTempFile, false, true);
    // Now validate
    RetryingTransactionCallback<Void> validate = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            ContentReader reader = contentService.getReader(shuffledNodeRef, ContentModel.PROP_CONTENT);
            String s = reader.getContentString();
            assertEquals("content not written", UPDATE_TEXT, s);
            assertTrue("node is not versionable", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertEquals("shuffledNode ref is different", shuffledNodeRef, testContext.testNodeRef);
            return null;
        }
    };
    tran.doInTransaction(validate, false, true);
    logger.debug("end testGedit");
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) ContentReader(org.alfresco.service.cmr.repository.ContentReader) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileExistsException(org.alfresco.jlan.server.filesys.FileExistsException) FileNotFoundException(java.io.FileNotFoundException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 3 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testRenameFile.

// testFileExists
/**
 * Unit test of rename file
 */
public void testRenameFile() throws Exception {
    logger.debug("testRenameFile");
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    final String FILE_PATH1 = TEST_ROOT_DOS_PATH + "\\SourceFile1.new";
    final String FILE_NAME2 = "SourceFile2.new";
    final String FILE_PATH2 = TEST_ROOT_DOS_PATH + "\\" + FILE_NAME2;
    final String FILE_PATH3 = TEST_ROOT_DOS_PATH + "\\SourceFile3.new";
    FileOpenParams dirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadOnly, FileAttribute.NTDirectory, 0);
    driver.createDirectory(testSession, testConnection, dirParams);
    FileOpenParams params1 = new FileOpenParams(FILE_PATH1, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    final NetworkFile file1 = driver.createFile(testSession, testConnection, params1);
    FileOpenParams params3 = new FileOpenParams(FILE_PATH3, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    final NetworkFile file3 = driver.createFile(testSession, testConnection, params3);
    /**
     * Step 1 : Negative test, Call Rename for a file which does not exist
     */
    try {
        driver.renameFile(testSession, testConnection, "\\Wibble\\wobble", FILE_PATH1);
        fail("rename did not detect missing file");
    } catch (IOException e) {
    // expect to go here
    }
    /**
     * Step 2: Negative test, Call Rename for a destination that does not exist.
     */
    try {
        driver.renameFile(testSession, testConnection, FILE_PATH1, "\\wibble\\wobble");
        fail("rename did not detect missing file");
    } catch (IOException e) {
    // expect to go here
    }
    /**
     * Step 3: Rename a file to a destination that is a file rather than a directory
     */
    try {
        driver.renameFile(testSession, testConnection, FILE_PATH1, FILE_PATH3);
        fail("rename did not detect missing file");
    } catch (IOException e) {
    // expect to go here
    }
    /**
     * Step 4: Successfully rename a file - check the name, props and content.
     */
    final String LAST_NAME = "Bloggs";
    RetryingTransactionCallback<Void> setPropertiesCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            final NodeRef file1NodeRef = getNodeForPath(testConnection, FILE_PATH1);
            assertNotNull("node ref not found", file1NodeRef);
            nodeService.setProperty(file1NodeRef, ContentModel.PROP_LASTNAME, LAST_NAME);
            return null;
        }
    };
    tran.doInTransaction(setPropertiesCB, false, true);
    driver.renameFile(testSession, testConnection, FILE_PATH1, FILE_PATH2);
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef file2NodeRef = getNodeForPath(testConnection, FILE_PATH2);
            // assertEquals("node ref has changed on a rename", file1NodeRef, file2NodeRef);
            assertEquals(nodeService.getProperty(file2NodeRef, ContentModel.PROP_LASTNAME), LAST_NAME);
            ChildAssociationRef parentRef = nodeService.getPrimaryParent(file2NodeRef);
            assertTrue("file has wrong assoc local name", parentRef.getQName().getLocalName().equals(FILE_NAME2));
            assertTrue("not primary assoc", parentRef.isPrimary());
            return null;
        }
    };
    tran.doInTransaction(validateCB, false, true);
    /**
     * Step 5: Rename to another directory
     */
    String DIR_NEW_PATH = TEST_ROOT_DOS_PATH + "\\NewDir";
    final String NEW_PATH = DIR_NEW_PATH + "\\File2";
    FileOpenParams params5 = new FileOpenParams(DIR_NEW_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    driver.createDirectory(testSession, testConnection, params5);
    final NodeRef newDirNodeRef = getNodeForPath(testConnection, DIR_NEW_PATH);
    driver.renameFile(testSession, testConnection, FILE_PATH2, NEW_PATH);
    RetryingTransactionCallback<Void> validateStep5CB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef file5NodeRef = getNodeForPath(testConnection, NEW_PATH);
            ChildAssociationRef parentRef5 = nodeService.getPrimaryParent(file5NodeRef);
            assertTrue(parentRef5.getParentRef().equals(newDirNodeRef));
            return null;
        }
    };
    tran.doInTransaction(validateStep5CB, false, true);
// /**
// * Step 5: rename to self - check no damage.
// */
// try
// {
// driver.renameFile(testSession, testConnection, FILE_PATH2, FILE_PATH2);
// fail("rename did not detect rename to self");
// }
// catch (IOException e)
// {
// expect to go here
// }
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) IOException(java.io.IOException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 4 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testExcel2003SaveShuffle.

/**
 * Excel 2003 With Versionable file
 *
 * CreateFile 5EE27100
 * RenameFile oldPath:\Espaces Utilisateurs\System\Cherries.xls,
 *          newPath:\Espaces Utilisateurs\System\Cherries.xls~RF172f241.TMP
 * RenameFile oldName=\Espaces Utilisateurs\System\5EE27100,
 *          newName=\Espaces Utilisateurs\System\Cherries.xls, session:WNB0
 *
 * Set Delete On Close for Cherries.xls~RF172f241.TMP
 */
public void testExcel2003SaveShuffle() throws Exception {
    // fail("not yet implemented");
    logger.debug("testScenarioExcel2003SaveShuffle");
    final String FILE_NAME = "Cherries.xls";
    final String FILE_TITLE = "Cherries";
    final String FILE_DESCRIPTION = "This is a test document to test CIFS shuffle";
    final String FILE_OLD_TEMP = "Cherries.xls~RF172f241.TMP";
    final String FILE_NEW_TEMP = "5EE27100";
    final QName RESIDUAL_MTTEXT = QName.createQName("{gsxhjsx}", "whatever");
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile newFileHandle;

        NetworkFile oldFileHandle;

        // node ref of test.doc
        NodeRef testNodeRef;

        Serializable testCreatedDate;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMSExcel2003SaveShuffle";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Clean up just in case garbage is left from a previous run
     */
    RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            /**
             * Create the file we are going to use
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            // now load up the node with lots of other stuff that we will test to see if it gets preserved during the
            // shuffle.
            testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            // test non CM namespace property
            nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
            // test CM property not related to an aspect
            nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_ADDRESSEE, "Fred");
            nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_TITLE, FILE_TITLE);
            nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_DESCRIPTION, FILE_DESCRIPTION);
            /**
             * MLText value - also a residual value in a non cm namespace
             */
            MLText mltext = new MLText();
            mltext.addValue(Locale.FRENCH, "Bonjour");
            mltext.addValue(Locale.ENGLISH, "Hello");
            mltext.addValue(Locale.ITALY, "Buongiorno");
            mlAwareNodeService.setProperty(testContext.testNodeRef, RESIDUAL_MTTEXT, mltext);
            // classifiable chosen since its not related to any properties.
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_CLASSIFIABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * Write some content to the test file
     */
    RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            String testContent = "MS Excel 2003 shuffle test";
            byte[] testContentBytes = testContent.getBytes();
            testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            testContext.firstFileHandle.close();
            testContext.testCreatedDate = nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_CREATED);
            MLText multi = (MLText) mlAwareNodeService.getProperty(testContext.testNodeRef, RESIDUAL_MTTEXT);
            multi.getValues();
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * b) Save the new file
     */
    RetryingTransactionCallback<Void> saveNewFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.newFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.newFileHandle);
            String testContent = "MS Word 2003 shuffle test This is new content";
            byte[] testContentBytes = testContent.getBytes();
            testContext.newFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            testContext.newFileHandle.close();
            return null;
        }
    };
    tran.doInTransaction(saveNewFileCB, false, true);
    /**
     * rename the old file
     */
    RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_OLD_TEMP);
            return null;
        }
    };
    tran.doInTransaction(renameOldFileCB, false, true);
    RetryingTransactionCallback<Void> validateOldFileGoneCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            try {
                driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            } catch (IOException e) {
            // expect to go here since previous step renamed the file.
            }
            return null;
        }
    };
    tran.doInTransaction(validateOldFileGoneCB, false, true);
    /**
     * Move the new file into place, stuff should get shuffled
     */
    RetryingTransactionCallback<Void> moveNewFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(moveNewFileCB, false, true);
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
            // Check trx:enabled has been shuffled.
            assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
            // check my residual MLText has been transferred
            assertTrue(props.containsKey(RESIDUAL_MTTEXT));
            // Check the titled aspect is correct
            assertEquals("name wrong", FILE_NAME, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_NAME));
            assertEquals("title wrong", FILE_TITLE, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_TITLE));
            assertEquals("description wrong", FILE_DESCRIPTION, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_DESCRIPTION));
            // assertEquals("noderef changed", testContext.testNodeRef, shuffledNodeRef);
            return null;
        }
    };
    tran.doInTransaction(validateCB, true, true);
    /**
     * Clean up just in case garbage is left from a previous run
     */
    RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_OLD_TEMP);
            return null;
        }
    };
    tran.doInTransaction(deleteOldFileCB, false, true);
}
Also used : Serializable(java.io.Serializable) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) IOException(java.io.IOException) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileExistsException(org.alfresco.jlan.server.filesys.FileExistsException) FileNotFoundException(java.io.FileNotFoundException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) MLText(org.alfresco.service.cmr.repository.MLText) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 5 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testNFS.

// Test Word 7 Explorer Update
/**
 * 0. test.txt and ~test.txt exist.
 * 1. Delete test.txt
 * 2. Rename test.txt~ to test.txt
 */
public void testNFS() throws Exception {
    logger.debug("testNFS()");
    final String FILE_NAME = "test.txt";
    final String FILE_NAME_TEMP = "test.txt~";
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile tempFileHandle;

        NodeRef file1NodeRef;
    }
    ;
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testNFS";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "cifs", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Clean up just in case garbage is left from a previous run
     */
    RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    RetryingTransactionCallback<Void> deleteGarbageFileCB2 = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME_TEMP);
            return null;
        }
    };
    try {
        logger.debug("expect to get exception - cleaning garbage");
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    try {
        logger.debug("expect to get exception - cleaning garbage");
        tran.doInTransaction(deleteGarbageFileCB2);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("0) create new file");
    RetryingTransactionCallback<TestContext> setupCB = new RetryingTransactionCallback<TestContext>() {

        @Override
        public TestContext execute() throws Throwable {
            TestContext ctx = new TestContext();
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            /**
             * Create the file we are going to use
             */
            {
                FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
                ctx.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
                assertNotNull(ctx.firstFileHandle);
                driver.closeFile(testSession, testConnection, ctx.firstFileHandle);
                ctx.file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            }
            {
                FileOpenParams createTempFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
                ctx.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
                assertNotNull(ctx.tempFileHandle);
                driver.closeFile(testSession, testConnection, ctx.tempFileHandle);
            }
            return ctx;
        }
    };
    final TestContext testContext = tran.doInTransaction(setupCB, false, true);
    /**
     * 1) delete the old file
     */
    logger.debug("1) delete old file");
    RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(deleteOldFileCB, false, true);
    logger.debug("2) remame temp file");
    RetryingTransactionCallback<Void> renameTempFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME_TEMP, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(renameTempFileCB, false, true);
    logger.debug("3) validate results");
    /**
     * Now validate everything is correct
     */
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
            // assertTrue("versionable aspect missing", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertEquals("Node ref has changed", shuffledNodeRef, testContext.file1NodeRef);
            return null;
        }
    };
    tran.doInTransaction(validateCB, true, true);
    logger.debug("end testNFS");
}
Also used : Serializable(java.io.Serializable) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileExistsException(org.alfresco.jlan.server.filesys.FileExistsException) FileNotFoundException(java.io.FileNotFoundException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Aggregations

DiskSharedDevice (org.alfresco.jlan.server.filesys.DiskSharedDevice)50 SrvSession (org.alfresco.jlan.server.SrvSession)47 ServerConfiguration (org.alfresco.jlan.server.config.ServerConfiguration)47 TreeConnection (org.alfresco.jlan.server.filesys.TreeConnection)47 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)46 NodeRef (org.alfresco.service.cmr.repository.NodeRef)46 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)45 FileOpenParams (org.alfresco.jlan.server.filesys.FileOpenParams)44 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)44 IOException (java.io.IOException)31 Serializable (java.io.Serializable)31 QName (org.alfresco.service.namespace.QName)26 DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)25 FileExistsException (org.alfresco.jlan.server.filesys.FileExistsException)25 FileNotFoundException (java.io.FileNotFoundException)24 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)24 PermissionDeniedException (org.alfresco.jlan.server.filesys.PermissionDeniedException)24 ContentData (org.alfresco.service.cmr.repository.ContentData)14 ClassPathResource (org.springframework.core.io.ClassPathResource)12 InputStream (java.io.InputStream)7