diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index ee7ca465db4b30559a3cb3c70fa6cf11a535b54e..e18a35bcc4fffd08ec4ab17f6e3d34d557999c03 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -18,6 +18,7 @@ set(JAVA_SOURCE_FILES java/src/org/opengroup/openvds/BufferUtils.java java/src/org/opengroup/openvds/Cleaner.java java/src/org/opengroup/openvds/CompressionMethod.java + java/src/org/opengroup/openvds/ConnectionErrorInfo.java java/src/org/opengroup/openvds/DimensionsND.java java/src/org/opengroup/openvds/experimental/VariousJavaTests.java java/src/org/opengroup/openvds/GoogleOpenOptions.java @@ -97,7 +98,9 @@ set(JAVA_TEST_SOURCES_FILES java/test/org/opengroup/openvds/CreateVDSTest.java java/test/org/opengroup/openvds/WriteDataTest.java java/test/org/opengroup/openvds/MetaDataContainerTest.java - java/test/org/opengroup/openvds/PageAccessorTest.java + java/test/org/opengroup/openvds/PageAccessorByteTest.java + java/test/org/opengroup/openvds/PageAccessorFloatTest.java + java/test/org/opengroup/openvds/PageAccessorShortTest.java ) add_jar(openvds-java-test diff --git a/java/cpp/src/MetadataContainer.cpp b/java/cpp/src/MetadataContainer.cpp index d99ca48b05bcfe777479b1cb9018baff701a53f6..7c6bf07646f709f59675e9618ce4bb761bb28342 100644 --- a/java/cpp/src/MetadataContainer.cpp +++ b/java/cpp/src/MetadataContainer.cpp @@ -285,6 +285,23 @@ JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadat CATCH_EXCEPTIONS_FOR_JAVA; } +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataBLOB + * Signature: (JLjava/lang/String;Ljava/lang/String;[B)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataBLOB + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jbyteArray valueArray) +{ + try { + int valueSize = env->GetArrayLength(valueArray); + jbyte *src = env->GetByteArrayElements(valueArray, NULL); + GetAccess( handle )->SetMetadataBLOB(JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), src, valueSize); + env->ReleaseByteArrayElements(valueArray, src, 0); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + #ifdef __cplusplus } #endif diff --git a/java/cpp/src/MetadataReadAccess.cpp b/java/cpp/src/MetadataReadAccess.cpp index dfd120d1e6896d1a9a56416fa9f4da83ec793ed7..817ea74f6f2ad35285d74dfad371b6585d4562a5 100644 --- a/java/cpp/src/MetadataReadAccess.cpp +++ b/java/cpp/src/MetadataReadAccess.cpp @@ -443,6 +443,27 @@ extern "C" { return NULL; } + /* + * Class: org_opengroup_openvds_MetadataReadAccess + * Method: cpGetMetadataBLOB + * Signature: (JLjava/lang/String;Ljava/lang/String;)[B + */ + JNIEXPORT jbyteArray JNICALL Java_org_opengroup_openvds_MetadataReadAccess_cpGetMetadataBLOB + (JNIEnv *env, jclass, jlong handle, jstring category, jstring name) + { + try { + // read blob + std::vector blob; + GetAccess( handle )->GetMetadataBLOB(JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), blob ); + + // convert to array + const char* blobArray = reinterpret_cast(blob.data()); + return NewJByteArray(env, blobArray, blob.size()); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return NULL; + } + /* * Class: org_opengroup_openvds_MetadataReadAccess * Method: cpGetMetadataKeys diff --git a/java/cpp/src/VolumeDataAccessManager.cpp b/java/cpp/src/VolumeDataAccessManager.cpp index 0968092d706750aed776108c88c710bf8adec279..c6f723afc65da54435b3775bf72441c0d8965df5 100644 --- a/java/cpp/src/VolumeDataAccessManager.cpp +++ b/java/cpp/src/VolumeDataAccessManager.cpp @@ -583,6 +583,67 @@ JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpGetC return 0; } +/* + * Class: org_opengroup_openvds_VolumeDataAccessManager + * Method: cpGetCurrentUploadErrorInfo + * Signature: (JLorg/opengroup/openvds/ErrorInfo;)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpGetCurrentUploadErrorInfo + (JNIEnv * env, jclass, jlong handle, jobject errorObj) +{ + try { + const char *pObjectID = nullptr; + const char *pErrorString = nullptr; + int32_t errorCode = 0; + + GetManager(handle)->GetCurrentUploadError(&pObjectID, &errorCode, &pErrorString); + + // Get the class of the given error object + jclass clazz = env->GetObjectClass(errorObj); + + // Get Field references + jfieldID paramCode = env->GetFieldID(clazz, "errorCode", "I"); + jfieldID paramMessage = env->GetFieldID(clazz, "errorMessage", "Ljava/lang/String;"); + jfieldID paramID = env->GetFieldID(clazz, "objectID", "Ljava/lang/String;"); + + // Set fields for object + jstring strMsg = NewJString(env, pErrorString); + jstring strID = NewJString(env, pObjectID); + env->SetIntField(errorObj, paramCode, errorCode); + env->SetObjectField(errorObj, paramMessage, strMsg); + env->SetObjectField(errorObj, paramID, strID); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_VolumeDataAccessManager + * Method: cpGetCurrentDownloadErrorInfo + * Signature: (JLorg/opengroup/openvds/ErrorInfo;)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpGetCurrentDownloadErrorInfo + (JNIEnv * env, jclass, jlong handle, jobject errorObj) +{ + try { + const char *pErrorString = nullptr; + int32_t errorCode = 0; + GetManager(handle)->GetCurrentDownloadError(&errorCode, &pErrorString); + + // Get the class of the given error object + jclass clazz = env->GetObjectClass(errorObj); + + // Get Field references + jfieldID paramCode = env->GetFieldID(clazz, "errorCode", "I"); + jfieldID paramMessage = env->GetFieldID(clazz, "errorMessage", "Ljava/lang/String;"); + + // Set fields for object + env->SetIntField(errorObj, paramCode, errorCode); + jstring strMsg = NewJString(env, pErrorString); + env->SetObjectField(errorObj, paramMessage, strMsg); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + #ifdef __cplusplus } #endif diff --git a/java/cpp/src/VolumeDataPage.cpp b/java/cpp/src/VolumeDataPage.cpp index 5309d03dd0727029808e45f866b4df24ee8c7504..3b1cc84394706ccbdfcc34c21073fddfcae0b748 100644 --- a/java/cpp/src/VolumeDataPage.cpp +++ b/java/cpp/src/VolumeDataPage.cpp @@ -242,6 +242,47 @@ extern "C" { CATCH_EXCEPTIONS_FOR_JAVA; } + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpGetShortBuffer + * Signature: (J[II)[S + */ + JNIEXPORT jshortArray JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpGetShortBuffer + (JNIEnv * env, jclass, jlong handle, jintArray pitchParam, jint lod) + { + try { + int pitch[OpenVDS::Dimensionality_Max]; + OpenVDS::VolumeDataPage* page = GetVolumePage(handle); + + const short* readData = (const short*)page->GetBuffer(pitch); + env->SetIntArrayRegion(pitchParam, 0, OpenVDS::Dimensionality_Max, (jint *)pitch); + int nbElem = GetBufferAllocatedSize(page); + return NewJShortArray(env, readData, nbElem); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return NULL; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpSetShortBuffer + * Signature: (J[S)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpSetShortBuffer + (JNIEnv * env, jclass, jlong handle, jshortArray values) + { + try { + OpenVDS::VolumeDataPage * page = GetVolumePage(handle); + int pitch[OpenVDS::Dimensionality_Max]; + short* pageBuffer = (short*)page->GetWritableBuffer(pitch); + int valueSize = env->GetArrayLength(values); + jshort *src = env->GetShortArrayElements(values, NULL); + std::memcpy(pageBuffer, src, valueSize * sizeof (short)); + env->ReleaseShortArrayElements(values, src, 0); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + #ifdef __cplusplus } #endif diff --git a/java/java/demo/CreateVDS.java b/java/java/demo/CreateVDS.java index 0931bd120c66a3ed6eef538f08444cc78bffd153..964a84fa2ed3021760f6a9819f0fd246c416f83f 100644 --- a/java/java/demo/CreateVDS.java +++ b/java/java/demo/CreateVDS.java @@ -157,7 +157,7 @@ public class CreateVDS { true, // is renderable false, // allow lossy compression false, // use zip for lossless compresion - true, // use no value + false, // use no value -999.25f, // no value scaleOffset[0], // integer scale scaleOffset[1]); // integer offset diff --git a/java/java/src/org/opengroup/openvds/BufferUtils.java b/java/java/src/org/opengroup/openvds/BufferUtils.java index cf98b05edf2ca52f43a01f0f5bc3924f29c63e87..8cc9e001a80459917fa3fa846278cd66e0412aef 100644 --- a/java/java/src/org/opengroup/openvds/BufferUtils.java +++ b/java/java/src/org/opengroup/openvds/BufferUtils.java @@ -27,6 +27,14 @@ import java.nio.ShortBuffer; import java.util.Objects; public abstract class BufferUtils { + /** + * @param array Th array to be copied into the new buffer + * @return A direct buffer copy of the given array + */ + public static ByteBuffer toBuffer(byte[] array) { + return (ByteBuffer) createByteBuffer(array.length).put(array).clear(); + } + /** * @param array Th array to be copied into the new buffer * @return A direct buffer copy of the given array diff --git a/java/java/src/org/opengroup/openvds/ConnectionErrorInfo.java b/java/java/src/org/opengroup/openvds/ConnectionErrorInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..c1584d911671e230dd13dd57425b49ca21ddbcb3 --- /dev/null +++ b/java/java/src/org/opengroup/openvds/ConnectionErrorInfo.java @@ -0,0 +1,43 @@ +package org.opengroup.openvds; + +/** + * Simple class holding information on Upload/Download error + */ +public class ConnectionErrorInfo { + + private int errorCode = -1; + private String errorMessage; + private String objectID; + + public ConnectionErrorInfo() { } + + public ConnectionErrorInfo(int code, String msg, String id) { + errorCode = code; + errorMessage = msg; + objectID = id; + } + + public int getErrorCode() { + return errorCode; + } + + public void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getObjectID() { + return objectID; + } + + public void setObjectID(String objectID) { + this.objectID = objectID; + } +} diff --git a/java/java/src/org/opengroup/openvds/MetadataContainer.java b/java/java/src/org/opengroup/openvds/MetadataContainer.java index e156e11c2cea30f2648a2e6c154ceebdf3f411f0..fdfb8e6a06354807584d96fd3fe4ed789cba6e0a 100644 --- a/java/java/src/org/opengroup/openvds/MetadataContainer.java +++ b/java/java/src/org/opengroup/openvds/MetadataContainer.java @@ -17,8 +17,7 @@ package org.opengroup.openvds; -import java.util.HashMap; -import java.util.Map; +import java.nio.ByteBuffer; public class MetadataContainer extends MetadataReadAccess { @@ -52,6 +51,8 @@ public class MetadataContainer extends MetadataReadAccess { private static native void cpSetMetadataString(long handle, String category, String name, String value); + private static native void cpSetMetadataBLOB(long handle, String category, String name, byte[] blobValues); + /** * Constructor around existing JNI object * @param handle jni pointer to existing container @@ -204,6 +205,32 @@ public class MetadataContainer extends MetadataReadAccess { cpSetMetadataString(_handle, category, name, value); } + /** + * set Meta data blob using a byte array + * @param category + * @param name + * @param blobValues + */ + public void setMetadataBLOB(String category, String name, byte[] blobValues) { + if (blobValues == null) { + throw new IllegalArgumentException("Blob values array is null."); + } + cpSetMetadataBLOB(_handle, category, name, blobValues); + } + + /** + * set Meta data blob using a byte array + * @param category + * @param name + * @param blobValues + */ + public void setMetadataBLOB(String category, String name, ByteBuffer blobValues) { + if (blobValues == null) { + throw new IllegalArgumentException("Blob values buffer is null."); + } + cpSetMetadataBLOB(_handle, category, name, blobValues.array()); + } + private void checkArrayArgument(int[] array, int expectedSize) { if (array == null || array.length != expectedSize) { diff --git a/java/java/src/org/opengroup/openvds/MetadataReadAccess.java b/java/java/src/org/opengroup/openvds/MetadataReadAccess.java index bf36af10820447c6517504e9724c4a269e482036..bc9e598e6fe147997a9df3ad6863254b6f4ebb06 100644 --- a/java/java/src/org/opengroup/openvds/MetadataReadAccess.java +++ b/java/java/src/org/opengroup/openvds/MetadataReadAccess.java @@ -17,6 +17,8 @@ package org.opengroup.openvds; +import java.nio.ByteBuffer; + public class MetadataReadAccess extends JniPointerWithoutDeletion { private static native boolean cpIsMetadataIntAvailable(long handle, String category, String name); @@ -73,6 +75,8 @@ public class MetadataReadAccess extends JniPointerWithoutDeletion { private static native String cpGetMetadataString(long handle, String category, String name); + private static native byte[] cpGetMetadataBLOB(long handle, String category, String name); + private static native MetadataKey[] cpGetMetadataKeys(long handle); public MetadataReadAccess(long handle) { @@ -337,6 +341,27 @@ public class MetadataReadAccess extends JniPointerWithoutDeletion { return cpGetMetadataString(_handle, category, name); } + /** + * get Metadata blob as byte array + * @param category + * @param name + * @return + */ + public byte[] getMetadataBLOB(String category, String name) { + return cpGetMetadataBLOB(_handle, category, name); + } + + /** + * get Metadata blob as byte buffer + * @param category + * @param name + * @return + */ + public ByteBuffer getMetadataBLOBAsBuffer(String category, String name) { + byte[] blobArray = cpGetMetadataBLOB(_handle, category, name); + return ByteBuffer.wrap(blobArray); + } + /** * @return an array of metadata keys */ diff --git a/java/java/src/org/opengroup/openvds/VolumeDataAccessManager.java b/java/java/src/org/opengroup/openvds/VolumeDataAccessManager.java index 2af400d2f89f9e8c2d6e25f724f7aa956714d369..506ac63e48b42b1c492e53eb771d3e72c8a1f0d4 100644 --- a/java/java/src/org/opengroup/openvds/VolumeDataAccessManager.java +++ b/java/java/src/org/opengroup/openvds/VolumeDataAccessManager.java @@ -147,6 +147,10 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { private static native int cpGetCurrentUploadErrorCode(long handle); + private static native void cpGetCurrentUploadErrorInfo(long handle, ConnectionErrorInfo error); + + private static native void cpGetCurrentDownloadErrorInfo(long handle, ConnectionErrorInfo error); + public VolumeDataAccessManager(long handle) { super(handle); } @@ -771,4 +775,22 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { public int getCurrentUploadErrorCode() { return cpGetCurrentUploadErrorCode(_handle); } + + /** + * @return current upload error information (code and message in a simple class) + */ + public ConnectionErrorInfo getCurrentUploadErrorInfo() { + ConnectionErrorInfo connectionErrorInfo = new ConnectionErrorInfo(); + cpGetCurrentUploadErrorInfo(_handle, connectionErrorInfo); + return connectionErrorInfo; + } + + /** + * @return current upload error information (code and message in a simple class) + */ + public ConnectionErrorInfo getCurrentDownloadErrorInfo() { + ConnectionErrorInfo connectionErrorInfo = new ConnectionErrorInfo(); + cpGetCurrentDownloadErrorInfo(_handle, connectionErrorInfo); + return connectionErrorInfo; + } } diff --git a/java/java/src/org/opengroup/openvds/VolumeDataPage.java b/java/java/src/org/opengroup/openvds/VolumeDataPage.java index 262cce4e590a69f7de7d828f485a2b78e3be0798..c80203c3d812e8ba84e878ddef46283464ff1ad3 100644 --- a/java/java/src/org/opengroup/openvds/VolumeDataPage.java +++ b/java/java/src/org/opengroup/openvds/VolumeDataPage.java @@ -41,6 +41,11 @@ public class VolumeDataPage extends JniPointerWithoutDeletion { private static native void cpSetDoubleBuffer(long handle, double[] buffer); + private static native short[] cpGetShortBuffer(long handle, int[] pitch, int lod); + + private static native void cpSetShortBuffer(long handle, short[] buffer); + + private final int dimensionality; private final int lod; @@ -144,6 +149,26 @@ public class VolumeDataPage extends JniPointerWithoutDeletion { cpSetFloatBuffer(_handle, buffer); } + /** + * Read short array of page + * @param pitch will receive pitch values for this page + * @return the short array of page data + */ + public short[] readShortBuffer(int[] pitch) { + checkDimParamArray(pitch, "Wrong pitch array parameter size, expected "); + return cpGetShortBuffer(_handle, pitch, lod); + } + + /** + * Set short array int page + * @param buffer values to set. Size must match page sample size + * @param pitch chunk pitch (got by a read) + */ + public void writeShortBuffer(short[] buffer, int[] pitch) { + checkBufferSize(buffer, pitch, dimensionality, lod); + cpSetShortBuffer(_handle, buffer); + } + /** * Read double array of page * @param pitch will receive pitch values for this page @@ -192,6 +217,13 @@ public class VolumeDataPage extends JniPointerWithoutDeletion { checkBufferSize(buffer.length, pitch, dimensionality, lod); } + private void checkBufferSize(short[] buffer, int[] pitch, int dim, int lod) { + if (buffer == null) { + throw new IllegalArgumentException("Wrong buffer size, got NULL"); + } + checkBufferSize(buffer.length, pitch, dimensionality, lod); + } + private void checkBufferSize(int sizeInputBuffer, int[] pitch, int dim, int lod) { int pageBufferSize = getAllocatedBufferSize(); if (sizeInputBuffer != pageBufferSize) { diff --git a/java/java/test/org/opengroup/openvds/MetaDataContainerTest.java b/java/java/test/org/opengroup/openvds/MetaDataContainerTest.java index 79b5d4ca9dc658bf41cd5a7f5814f76e5b5a5396..92786bbdc52176f6ed8760a178cfe7e9369b1fdd 100644 --- a/java/java/test/org/opengroup/openvds/MetaDataContainerTest.java +++ b/java/java/test/org/opengroup/openvds/MetaDataContainerTest.java @@ -17,11 +17,15 @@ package org.opengroup.openvds; +import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.File; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.util.Random; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; @@ -308,4 +312,66 @@ public class MetaDataContainerTest { } } + @Test + public void testMetaDataBlob() { + MetadataContainer metaData = new MetadataContainer(); + + byte[] blobArray = new byte[3200]; + Random rand = new Random(System.currentTimeMillis()); + rand.nextBytes(blobArray); + + metaData.setMetadataBLOB("Blob data", "blob array", blobArray); + + Assert.assertTrue(metaData.isMetadataBLOBAvailable("Blob data", "blob array")); + byte[] metadataBLOBArray = metaData.getMetadataBLOB("Blob data", "blob array"); + Assert.assertEquals(blobArray, metadataBLOBArray); + } + + @Test + public void testMetaDataBlobBuffer() { + MetadataContainer metaData = new MetadataContainer(); + + byte[] blobArray = new byte[3200]; + Random rand = new Random(System.currentTimeMillis()); + rand.nextBytes(blobArray); + + ByteBuffer blobBuffer = ByteBuffer.wrap(blobArray); + metaData.setMetadataBLOB("Blob data", "blob array", blobBuffer); + + Assert.assertTrue(metaData.isMetadataBLOBAvailable("Blob data", "blob array")); + ByteBuffer metadataBLOBBuffer = metaData.getMetadataBLOBAsBuffer("Blob data", "blob array"); + + // compares buffer + Assert.assertTrue(metadataBLOBBuffer.equals(blobBuffer)); + } + + @Test + public void testMetaDataBlobFloatBuffer() { + MetadataContainer metaData = new MetadataContainer(); + + // put floats in a byte buffer + float[] blobFloatArray = new float[2000]; + Random rand = new Random(System.currentTimeMillis()); + for (int i = 0 ; i < blobFloatArray.length ; ++i) { + blobFloatArray[i] = rand.nextFloat(); + } + ByteBuffer byteBuffer = ByteBuffer.allocate(Float.BYTES * blobFloatArray.length); + byteBuffer.asFloatBuffer().put(blobFloatArray); + + // writes them + metaData.setMetadataBLOB("Blob data", "blob array", byteBuffer); + + // reread and compare + Assert.assertTrue(metaData.isMetadataBLOBAvailable("Blob data", "blob array")); + ByteBuffer metadataBLOBBuffer = metaData.getMetadataBLOBAsBuffer("Blob data", "blob array"); + FloatBuffer metaDataFB = metadataBLOBBuffer.asFloatBuffer(); + int size = metaDataFB.remaining(); + float[] readFloats = new float[size]; + metaDataFB.get(readFloats); + + // compares buffer + Assert.assertEquals(blobFloatArray, readFloats); + } } + + diff --git a/java/java/test/org/opengroup/openvds/PageAccessorByteTest.java b/java/java/test/org/opengroup/openvds/PageAccessorByteTest.java new file mode 100644 index 0000000000000000000000000000000000000000..05a1b344df8ba6208e2312ead56ac52b97b656c5 --- /dev/null +++ b/java/java/test/org/opengroup/openvds/PageAccessorByteTest.java @@ -0,0 +1,335 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.File; + +import static org.testng.Assert.fail; + +public class PageAccessorByteTest { + + private static String TEMP_FILE_NAME_VOL_INDEX = "volIndexer"; + private static String TEMP_FILE_NAME_COPY = "vdsCopyByte"; + + public String url; + public VolumeDataLayoutDescriptor ld; + public VolumeDataAxisDescriptor[] vda; + public VolumeDataChannelDescriptor[] vdc; + public MetadataReadAccess md; + public MemoryVdsGenerator vds; + public MetadataContainer metadataContainer; + + private String tempVolIndexerFileName; + private String tempVdsCopyFileName; + + @BeforeClass + public void init() { + vds = new MemoryVdsGenerator(200, 200, 200, VolumeDataChannelDescriptor.Format.FORMAT_U8); + url = "inmemory://create_test"; + VolumeDataLayout volumeDataLayout = vds.getLayout(); + + int nbChannel = volumeDataLayout.getChannelCount(); + VolumeDataAccessManager accessManager = vds.getAccessManager(); + + for (VolumeDataLayoutDescriptor.LODLevels l : VolumeDataLayoutDescriptor.LODLevels.values()) { + for (int channel = 0; channel < nbChannel; channel++) { + for (DimensionsND dimGroup : DimensionsND.values()) { + VDSProduceStatus vdsProduceStatus = accessManager.getVDSProduceStatus(dimGroup, l.ordinal(), channel); + } + } + } + + vda = new VolumeDataAxisDescriptor[] { + volumeDataLayout.getAxisDescriptor(0), + volumeDataLayout.getAxisDescriptor(1), + volumeDataLayout.getAxisDescriptor(2)}; + vdc = new VolumeDataChannelDescriptor[] {volumeDataLayout.getChannelDescriptor(0)}; + + md = volumeDataLayout; + ld = volumeDataLayout.getLayoutDescriptor(); + + metadataContainer = new MetadataContainer(); + + long ms = System.currentTimeMillis(); + tempVolIndexerFileName = TEMP_FILE_NAME_VOL_INDEX + "_" + ms + ".vds"; + tempVdsCopyFileName = TEMP_FILE_NAME_COPY + "_" + ms + ".vds"; + } + + @AfterClass + public void cleanFiles() { + String tempDir = System.getProperty("java.io.tmpdir"); + String fileVolIndexPath = tempDir + File.separator + tempVolIndexerFileName; + File fileVolIndex = new File(fileVolIndexPath); + if (fileVolIndex.exists()) { + fileVolIndex.delete(); + } + + String fileCopyPath = tempDir + File.separator + tempVdsCopyFileName; + File fileCopy = new File(fileCopyPath); + if (fileCopy.exists()) { + fileCopy.delete(); + } + } + + @Test + public void testVolumeIndexerCreationDeletion() { + try { + // create file in tmp dir + String tmpDir = System.getProperty("java.io.tmpdir"); + String volIndexPath = tmpDir + File.separator + tempVolIndexerFileName; + VDSFileOpenOptions options = new VDSFileOpenOptions(volIndexPath); + VdsHandle vdsTest = OpenVDS.create(options, ld, + vda, + vdc, metadataContainer); + VolumeDataAccessManager accessManager = vdsTest.getAccessManager(); + //ASSERT_TRUE(accessManager); + + int channel = 0; + VolumeDataLayout layout = vdsTest.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 100, // max pages + VolumeDataPageAccessor.AccessMode.Create.getCode()); // access mode + + VolumeDataPage page = pageAccessor.createPage(0); + VolumeIndexer3D outputIndexer = new VolumeIndexer3D(page, 0, 0, DimensionsND.DIMENSIONS_012.ordinal(), layout); + outputIndexer.finalize(); + + vdsTest.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + @Test + public void testCopyPageAccessor() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + tempVdsCopyFileName; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + + // copy information from input VDS + VolumeDataLayoutDescriptor cpLd = new VolumeDataLayoutDescriptor( + ld.getBrickSize(), + ld.getNegativeMargin(), + ld.getPositiveMargin(), + ld.getBrickSizeMultiplier2D(), + ld.getLODLevels(), + ld.isCreate2DLODs(), + ld.isForceFullResolutionDimension(), + ld.getFullResolutionDimension() + ); + + VolumeDataAxisDescriptor[] cpVda = new VolumeDataAxisDescriptor[3]; + for (int i = 0 ; i < 3 ; ++i) { + cpVda[i] = new VolumeDataAxisDescriptor(vda[i].getNumSamples(), + vda[i].getName(), vda[i].getUnit(), + vda[i].getCoordinateMin(), vda[i].getCoordinateMax()); + } + + VolumeDataChannelDescriptor[] cpVdc = new VolumeDataChannelDescriptor[1]; + cpVdc[0] = new VolumeDataChannelDescriptor( + VolumeDataChannelDescriptor.Format.fromCode(vdc[0].getFormat()), + VolumeDataChannelDescriptor.Components.fromCode(vdc[0].getComponents()), + vdc[0].getName(), + vdc[0].getUnit(), + vdc[0].getValueRangeMin(), vdc[0].getValueRangeMax(), + VolumeDataMapping.fromCode(vdc[0].getMapping()), + vdc[0].getMappedValueCount(), + vdc[0].isDiscrete(), + vdc[0].isRenderable(), + vdc[0].isAllowLossyCompression(), + vdc[0].isUseZipForLosslessCompression(), + vdc[0].isUseNoValue(), + vdc[0].getNoValue(), + vdc[0].getIntegerScale(), + vdc[0].getIntegerOffset() + ); + MetadataContainer cpMetadataContainer = new MetadataContainer(); + VdsHandle vdsCopy = OpenVDS.create(options, cpLd, + cpVda, + cpVdc, + cpMetadataContainer); + + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + //ASSERT_TRUE(accessManager); + + int channel = 0; + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 100, // max pages + VolumeDataPageAccessor.AccessMode.Create.getCode()); // access mode + + // get input manager + VolumeDataAccessManager inputAM = vds.getAccessManager(); + VolumeDataPageAccessor pageAccessorInput = inputAM.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 100, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // copy file + int[] pitch = new int[VolumeDataLayout.Dimensionality_Max]; + long chunkCount = pageAccessorInput.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessorInput.readPage(chunk); + VolumeDataPage page = pageAccessor.createPage(chunk); + byte[] data = inputPage.readByteBuffer(pitch); + page.writeByteBuffer(data, pitch); + + inputPage.pageRelease(); + page.pageRelease(); + } + pageAccessor.commit(); + accessManager.flushUploadQueue(); + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + /** + * Will test that copied file is the same as the input + * Name of method is the same + Suffix so that it's executed after the copy test + */ + @Test + public void testCopyPageAccessorValidation() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + tempVdsCopyFileName; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + VdsHandle vdsCopy = OpenVDS.open(options); + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + + int channel = 0; + VolumeDataLayout layout = vdsCopy.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // get input manager + VolumeDataAccessManager inputAM = vds.getAccessManager(); + VolumeDataPageAccessor pageAccessorInput = inputAM.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // compares block data + int[] pitchInput = new int[VolumeDataLayout.Dimensionality_Max]; + int[] pitchOutput = new int[VolumeDataLayout.Dimensionality_Max]; + + long chunkCount = pageAccessorInput.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessorInput.readPage(chunk); + VolumeDataPage page = pageAccessor.readPage(chunk); + byte[] dataIn = inputPage.readByteBuffer(pitchInput); + byte[] dataOut = page.readByteBuffer(pitchOutput); + + inputPage.pageRelease(); + page.pageRelease(); + + Assert.assertEquals(pitchInput, pitchOutput); + Assert.assertEquals(dataIn, dataOut); + } + + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + /** + * Will test that copied file has the same layout than original (test that 3D positions are in the same chunk index) + * Name of method is the same + Suffix so that it's executed after the copy test + */ + @Test + public void testCopyPageAccessorValidationChunkIndex() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + tempVdsCopyFileName; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + VdsHandle vdsCopy = OpenVDS.open(options); + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + + int channel = 0; + VolumeDataLayout layout = vdsCopy.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // compares block data + int[] chunkMin = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMax = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMaxPos = new int[VolumeDataLayout.Dimensionality_Max]; + + long chunkCount = pageAccessor.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessor.readPage(chunk); + + // check that chunk index matches current index + inputPage.getMinMaxExcludingMargin(chunkMin, chunkMax); + for (int i = 0 ; i < VolumeDataLayout.Dimensionality_Max ; ++i) { + chunkMaxPos[i] = chunkMax[i] != 0 ? chunkMax[i] - 1 : chunkMax[i]; + } + long idxChMin = pageAccessor.getChunkIndex(chunkMin); + long idxChMax = pageAccessor.getChunkIndex(chunkMaxPos); + + Assert.assertEquals(chunk, idxChMin); + Assert.assertEquals(idxChMin, idxChMax); + + inputPage.pageRelease(); + } + + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } +} diff --git a/java/java/test/org/opengroup/openvds/PageAccessorTest.java b/java/java/test/org/opengroup/openvds/PageAccessorFloatTest.java similarity index 99% rename from java/java/test/org/opengroup/openvds/PageAccessorTest.java rename to java/java/test/org/opengroup/openvds/PageAccessorFloatTest.java index f1fa1f1fba0a9c818221aef18d8598460801d4db..00cb090068da16668b736380f3b4a6c659beede3 100644 --- a/java/java/test/org/opengroup/openvds/PageAccessorTest.java +++ b/java/java/test/org/opengroup/openvds/PageAccessorFloatTest.java @@ -27,10 +27,10 @@ import java.io.File; import static org.testng.Assert.fail; -public class PageAccessorTest { +public class PageAccessorFloatTest { private static String TEMP_FILE_NAME_VOL_INDEX = "volIndexer"; - private static String TEMP_FILE_NAME_COPY = "vdsCopy"; + private static String TEMP_FILE_NAME_COPY = "vdsFloatCopy"; public String url; public VolumeDataLayoutDescriptor ld; diff --git a/java/java/test/org/opengroup/openvds/PageAccessorShortTest.java b/java/java/test/org/opengroup/openvds/PageAccessorShortTest.java new file mode 100644 index 0000000000000000000000000000000000000000..15990e47b021e77544818ce3b4f51ff409283c0d --- /dev/null +++ b/java/java/test/org/opengroup/openvds/PageAccessorShortTest.java @@ -0,0 +1,335 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.File; + +import static org.testng.Assert.fail; + +public class PageAccessorShortTest { + + private static String TEMP_FILE_NAME_VOL_INDEX = "volIndexer"; + private static String TEMP_FILE_NAME_COPY = "vdsCopyShort"; + + public String url; + public VolumeDataLayoutDescriptor ld; + public VolumeDataAxisDescriptor[] vda; + public VolumeDataChannelDescriptor[] vdc; + public MetadataReadAccess md; + public MemoryVdsGenerator vds; + public MetadataContainer metadataContainer; + + private String tempVolIndexerFileName; + private String tempVdsCopyFileName; + + @BeforeClass + public void init() { + vds = new MemoryVdsGenerator(200, 200, 200, VolumeDataChannelDescriptor.Format.FORMAT_U16); + url = "inmemory://create_test"; + VolumeDataLayout volumeDataLayout = vds.getLayout(); + + int nbChannel = volumeDataLayout.getChannelCount(); + VolumeDataAccessManager accessManager = vds.getAccessManager(); + + for (VolumeDataLayoutDescriptor.LODLevels l : VolumeDataLayoutDescriptor.LODLevels.values()) { + for (int channel = 0; channel < nbChannel; channel++) { + for (DimensionsND dimGroup : DimensionsND.values()) { + VDSProduceStatus vdsProduceStatus = accessManager.getVDSProduceStatus(dimGroup, l.ordinal(), channel); + } + } + } + + vda = new VolumeDataAxisDescriptor[] { + volumeDataLayout.getAxisDescriptor(0), + volumeDataLayout.getAxisDescriptor(1), + volumeDataLayout.getAxisDescriptor(2)}; + vdc = new VolumeDataChannelDescriptor[] {volumeDataLayout.getChannelDescriptor(0)}; + + md = volumeDataLayout; + ld = volumeDataLayout.getLayoutDescriptor(); + + metadataContainer = new MetadataContainer(); + + long ms = System.currentTimeMillis(); + tempVolIndexerFileName = TEMP_FILE_NAME_VOL_INDEX + "_" + ms + ".vds"; + tempVdsCopyFileName = TEMP_FILE_NAME_COPY + "_" + ms + ".vds"; + } + + @AfterClass + public void cleanFiles() { + String tempDir = System.getProperty("java.io.tmpdir"); + String fileVolIndexPath = tempDir + File.separator + tempVolIndexerFileName; + File fileVolIndex = new File(fileVolIndexPath); + if (fileVolIndex.exists()) { + fileVolIndex.delete(); + } + + String fileCopyPath = tempDir + File.separator + tempVdsCopyFileName; + File fileCopy = new File(fileCopyPath); + if (fileCopy.exists()) { + fileCopy.delete(); + } + } + + @Test + public void testVolumeIndexerCreationDeletion() { + try { + // create file in tmp dir + String tmpDir = System.getProperty("java.io.tmpdir"); + String volIndexPath = tmpDir + File.separator + tempVolIndexerFileName; + VDSFileOpenOptions options = new VDSFileOpenOptions(volIndexPath); + VdsHandle vdsTest = OpenVDS.create(options, ld, + vda, + vdc, metadataContainer); + VolumeDataAccessManager accessManager = vdsTest.getAccessManager(); + //ASSERT_TRUE(accessManager); + + int channel = 0; + VolumeDataLayout layout = vdsTest.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 100, // max pages + VolumeDataPageAccessor.AccessMode.Create.getCode()); // access mode + + VolumeDataPage page = pageAccessor.createPage(0); + VolumeIndexer3D outputIndexer = new VolumeIndexer3D(page, 0, 0, DimensionsND.DIMENSIONS_012.ordinal(), layout); + outputIndexer.finalize(); + + vdsTest.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + @Test + public void testCopyPageAccessor() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + tempVdsCopyFileName; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + + // copy information from input VDS + VolumeDataLayoutDescriptor cpLd = new VolumeDataLayoutDescriptor( + ld.getBrickSize(), + ld.getNegativeMargin(), + ld.getPositiveMargin(), + ld.getBrickSizeMultiplier2D(), + ld.getLODLevels(), + ld.isCreate2DLODs(), + ld.isForceFullResolutionDimension(), + ld.getFullResolutionDimension() + ); + + VolumeDataAxisDescriptor[] cpVda = new VolumeDataAxisDescriptor[3]; + for (int i = 0 ; i < 3 ; ++i) { + cpVda[i] = new VolumeDataAxisDescriptor(vda[i].getNumSamples(), + vda[i].getName(), vda[i].getUnit(), + vda[i].getCoordinateMin(), vda[i].getCoordinateMax()); + } + + VolumeDataChannelDescriptor[] cpVdc = new VolumeDataChannelDescriptor[1]; + cpVdc[0] = new VolumeDataChannelDescriptor( + VolumeDataChannelDescriptor.Format.fromCode(vdc[0].getFormat()), + VolumeDataChannelDescriptor.Components.fromCode(vdc[0].getComponents()), + vdc[0].getName(), + vdc[0].getUnit(), + vdc[0].getValueRangeMin(), vdc[0].getValueRangeMax(), + VolumeDataMapping.fromCode(vdc[0].getMapping()), + vdc[0].getMappedValueCount(), + vdc[0].isDiscrete(), + vdc[0].isRenderable(), + vdc[0].isAllowLossyCompression(), + vdc[0].isUseZipForLosslessCompression(), + vdc[0].isUseNoValue(), + vdc[0].getNoValue(), + vdc[0].getIntegerScale(), + vdc[0].getIntegerOffset() + ); + MetadataContainer cpMetadataContainer = new MetadataContainer(); + VdsHandle vdsCopy = OpenVDS.create(options, cpLd, + cpVda, + cpVdc, + cpMetadataContainer); + + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + //ASSERT_TRUE(accessManager); + + int channel = 0; + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 100, // max pages + VolumeDataPageAccessor.AccessMode.Create.getCode()); // access mode + + // get input manager + VolumeDataAccessManager inputAM = vds.getAccessManager(); + VolumeDataPageAccessor pageAccessorInput = inputAM.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 100, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // copy file + int[] pitch = new int[VolumeDataLayout.Dimensionality_Max]; + long chunkCount = pageAccessorInput.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessorInput.readPage(chunk); + VolumeDataPage page = pageAccessor.createPage(chunk); + short[] data = inputPage.readShortBuffer(pitch); + page.writeShortBuffer(data, pitch); + + inputPage.pageRelease(); + page.pageRelease(); + } + pageAccessor.commit(); + accessManager.flushUploadQueue(); + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + /** + * Will test that copied file is the same as the input + * Name of method is the same + Suffix so that it's executed after the copy test + */ + @Test + public void testCopyPageAccessorValidation() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + tempVdsCopyFileName; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + VdsHandle vdsCopy = OpenVDS.open(options); + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + + int channel = 0; + VolumeDataLayout layout = vdsCopy.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // get input manager + VolumeDataAccessManager inputAM = vds.getAccessManager(); + VolumeDataPageAccessor pageAccessorInput = inputAM.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // compares block data + int[] pitchInput = new int[VolumeDataLayout.Dimensionality_Max]; + int[] pitchOutput = new int[VolumeDataLayout.Dimensionality_Max]; + + long chunkCount = pageAccessorInput.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessorInput.readPage(chunk); + VolumeDataPage page = pageAccessor.readPage(chunk); + short[] dataIn = inputPage.readShortBuffer(pitchInput); + short[] dataOut = page.readShortBuffer(pitchOutput); + + inputPage.pageRelease(); + page.pageRelease(); + + Assert.assertEquals(pitchInput, pitchOutput); + Assert.assertEquals(dataIn, dataOut); + } + + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + /** + * Will test that copied file has the same layout than original (test that 3D positions are in the same chunk index) + * Name of method is the same + Suffix so that it's executed after the copy test + */ + @Test + public void testCopyPageAccessorValidationChunkIndex() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + tempVdsCopyFileName; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + VdsHandle vdsCopy = OpenVDS.open(options); + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + + int channel = 0; + VolumeDataLayout layout = vdsCopy.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // compares block data + int[] chunkMin = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMax = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMaxPos = new int[VolumeDataLayout.Dimensionality_Max]; + + long chunkCount = pageAccessor.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessor.readPage(chunk); + + // check that chunk index matches current index + inputPage.getMinMaxExcludingMargin(chunkMin, chunkMax); + for (int i = 0 ; i < VolumeDataLayout.Dimensionality_Max ; ++i) { + chunkMaxPos[i] = chunkMax[i] != 0 ? chunkMax[i] - 1 : chunkMax[i]; + } + long idxChMin = pageAccessor.getChunkIndex(chunkMin); + long idxChMax = pageAccessor.getChunkIndex(chunkMaxPos); + + Assert.assertEquals(chunk, idxChMin); + Assert.assertEquals(idxChMin, idxChMax); + + inputPage.pageRelease(); + } + + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } +}