-
Notifications
You must be signed in to change notification settings - Fork 74
Closed
Description
A test uses FileHandle to bulkload 100+ binary documents, and then test bulk read from database. After the write to database, when reading back the URIs, the format of the documents returns as UNKNOWN instead of BINARY
Here is the documentation from pubs:
Unless the format is explicitly set when you load a document, the format of the document is determined based on the MIME type that corresponds to the URI extension of the new document. The URI extension MIME types, along with their default formats, are set in the Mimetypes section of the Admin Interface.
URI Document Type
/path/doc.json JSON
/path/doc.xml XML
/path/doc.jpg binary
/path/doc.txt text
@Test
public void test3ReadMultipleBinaryDoc() throws Exception
{
String docId[] = {"Sega-4MB.jpg"};
int count=1;
BinaryDocumentManager docMgr = client.newBinaryDocumentManager();
DocumentWriteSet writeset =docMgr.newWriteSet();
File file1= null;
file1 = new File("src/test/java/com/marklogic/client/functionaltest/data/" + docId[0]);
FileHandle h1 = new FileHandle(file1);
for(int i =0;i<102;i++){
writeset.add(DIRECTORY+"binary"+i+".jpg", h1);
if(count%BATCH_SIZE == 0){
docMgr.write(writeset);
writeset = docMgr.newWriteSet();
}
count++;
}
if(count%BATCH_SIZE > 0){
docMgr.write(writeset);
}
String uris[] = new String[102];
for(int i =0;i<102;i++){
uris[i]=DIRECTORY+"binary"+i+".jpg";
}
count=0;
FileHandle rh = new FileHandle();
DocumentPage page = docMgr.read(uris);
while(page.hasNext()){
DocumentRecord rec = page.next();
validateRecord(rec,Format.BINARY);
rec.getContent(rh);
assertEquals("Content length :",file1.length(),rh.get().length());
count++;
}
assertEquals("document count", 102,count);
//Testing the multiple same uris will not read multiple records
}
public void validateRecord(DocumentRecord record,Format type) {
assertNotNull("DocumentRecord should never be null", record);
assertNotNull("Document uri should never be null", record.getUri());
assertTrue("Document uri should start with " + DIRECTORY, record.getUri().startsWith(DIRECTORY));
assertEquals("All records are expected to be in same format", type, record.getFormat());
}
Here is the exception seen:
java.lang.AssertionError: All records are expected to be in same format expected:<BINARY> but was:<UNKNOWN>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:743)
at org.junit.Assert.assertEquals(Assert.java:118)
at com.marklogic.client.functionaltest.TestBulkReadSample1.validateRecord(TestBulkReadSample1.java:383)
at com.marklogic.client.functionaltest.TestBulkReadSample1.test3ReadMultipleBinaryDoc(TestBulkReadSample1.java:208)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)