Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform unused on DocumentManager.write(DocumentWriteSet, ServerTransform, Transaction) #396

Closed
sammefford opened this issue Mar 8, 2016 · 3 comments

Comments

@sammefford
Copy link
Contributor

The code for DocumentManager.write(DocumentWriteSet, ServerTransform, Transaction) was passing through the DocumentWriteSet and Transaction, but not the ServerTransform.

@sammefford sammefford added this to the java-client-api-3.0.5 milestone Mar 8, 2016
sammefford added a commit that referenced this issue Mar 8, 2016
…ntWriteSet, ServerTransform, Transaction)
@sammefford sammefford added test and removed fix labels Mar 8, 2016
@sammefford sammefford assigned sammefford and georgeajit and unassigned sammefford Mar 8, 2016
sammefford added a commit that referenced this issue Mar 10, 2016
…ntWriteSet, ServerTransform, Transaction)

(cherry picked from commit 9740ad5)
@georgeajit georgeajit added ship and removed test labels Mar 14, 2016
@georgeajit georgeajit removed their assignment Mar 14, 2016
@georgeajit
Copy link
Contributor

Added a test method to TestBulkWriteWithTransformations.

/* This test is similar to testBulkLoadWithXQueryTransform and is used to validate Git Issue 396.
     * 
     * Verify that a ServerTransform object is passed along when in transactions.
     */

    @Test
    public void testBulkXQYTransformWithTrans() throws Exception {

        TransformExtensionsManager transMgr = 
                client.newServerConfigManager().newTransformExtensionsManager();
        Transaction tRollback = client.openTransaction();
        ExtensionMetadata metadata = new ExtensionMetadata();
        metadata.setTitle("Adding attribute xquery Transform");
        metadata.setDescription("This plugin transforms an XML document by adding attribute to root node");
        metadata.setProvider("MarkLogic");
        metadata.setVersion("0.1");
        // get the transform file
        File transformFile = new File("src/test/java/com/marklogic/client/functionaltest/transforms/add-attr-xquery-transform.xqy");
        FileHandle transformHandle = new FileHandle(transformFile);
        transMgr.writeXQueryTransform("add-attr-xquery-transform", transformHandle, metadata);
        ServerTransform transform = new ServerTransform("add-attr-xquery-transform");
        transform.put("name", "Lang");
        transform.put("value", "English");
        int count=1;
        XMLDocumentManager docMgr = client.newXMLDocumentManager();
        HashMap<String,String> map= new HashMap<String,String>();
        DocumentWriteSet writesetRollback = docMgr.newWriteSet();
        // Verify rollback with a smaller number of documents.
        for(int i = 0;i<12;i++){

            writesetRollback.add(DIRECTORY+"fooWithTrans"+i+".xml", new DOMHandle(getDocumentContent("This is so foo"+i)));
            map.put(DIRECTORY+"fooWithTrans"+i+".xml", convertXMLDocumentToString(getDocumentContent("This is so foo"+i)));
            if(count%10 == 0){
                docMgr.write(writesetRollback, transform, tRollback);
                writesetRollback = docMgr.newWriteSet();
            }
            count++;
        }
        if(count%10 > 0){
            docMgr.write(writesetRollback, transform, tRollback);
        }
        String uris[] = new String[102];
        for(int i =0;i<102;i++){
            uris[i]=DIRECTORY+"fooWithTrans"+i+".xml";
        }

        try {
            // Verify rollback on DocumentManager write method with transform. 
            tRollback.rollback();           
            DocumentPage pageRollback = docMgr.read(uris);
            assertEquals("Document count is not zero. Transaction did not rollback", 0, pageRollback.size());

            // Perform write with a commit.
            Transaction tCommit = client.openTransaction();
            DocumentWriteSet writeset = docMgr.newWriteSet();
            for(int i =0;i<102;i++){

                writeset.add(DIRECTORY+"fooWithTrans"+i+".xml", new DOMHandle(getDocumentContent("This is so foo"+i)));
                map.put(DIRECTORY+"fooWithTrans"+i+".xml", convertXMLDocumentToString(getDocumentContent("This is so foo"+i)));
                if(count%BATCH_SIZE == 0){
                    docMgr.write(writeset, transform, tCommit);
                    writeset = docMgr.newWriteSet();
                }
                count++;
            }
            if(count%BATCH_SIZE > 0){
                docMgr.write(writeset, transform, tCommit);
            }
            tCommit.commit();           
            count=0;
            DocumentPage page = docMgr.read(uris);
            DOMHandle dh = new DOMHandle();
            while(page.hasNext()){
                DocumentRecord rec = page.next();
                rec.getContent(dh);
                assertTrue("Element has attribure ? :",dh.get().getElementsByTagName("foo").item(0).hasAttributes());
                count++;
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());throw e;
        }       
        assertEquals("document count", 102,count); 
    }

@sammefford
Copy link
Contributor Author

Ajit, I can see that this test validates that documents are written and rolled back when appropriate. But I can't tell if this test validates that the transform ran. Does it?

@georgeajit
Copy link
Contributor

Added verification to make sure that server transforms have occurred.

verifyAttrValue = dh.get().getElementsByTagName("foo").item(0).getAttributes().getNamedItem("Lang").getNodeValue();
assertTrue("Server Transform did not go through ",verifyAttrValue.equalsIgnoreCase("testBulkXQYTransformWithTrans"));


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants