hdf5/java/test/TestH5Pfaplhdfs.java

160 lines
5.5 KiB
Java
Raw Normal View History

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.exceptions.HDF5Exception;
import hdf.hdf5lib.exceptions.HDF5LibraryException;
import hdf.hdf5lib.structs.H5FD_hdfs_fapl_t;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
public class TestH5Pfaplhdfs {
2022-04-20 02:08:09 +08:00
@Rule
public TestName testname = new TestName();
2022-04-20 02:08:09 +08:00
long fapl_id = HDF5Constants.H5I_INVALID_HID;
long plapl_id = HDF5Constants.H5I_INVALID_HID;
long dapl_id = HDF5Constants.H5I_INVALID_HID;
long plist_id = HDF5Constants.H5I_INVALID_HID;
Primary change is HDFFV-11212 - new refs and JNI (#372) * OESS-98 convert plugin option to FetchContent, add tests * Fixes for pkcfg files because of plugin option * OESS-98 fix tools test for plugins * Keep doxygen comments under 100 chars long - format hint * Whitespace * HDFFV-11144 - Reclassify CMake messages * HDFFV-11099/11100 added help text * Reworked switch statement to compare string instead * Fix typo * Update CDash mode * Correct name of threadsafe * Correct option name * Undo accidental commit * Note LLVM 10 to 11 format default changes * Update format plugin * Undo clang-format version 11 changes * One more correction * Update supported platforms * Revert whitespace changes * Correct whitespace * Changes from PR#3 * HDFFV-11213 added option to control gcc10 warnings diagnostics * HDFFV-11212 Use the new references correctly in JNI utility and tests * format source * Fix typo * Add new test file * HDFFV-11212 - update test and remove unused arg * Minor non-space formatting changes * Use H5I_INVALID_ID instead of "-1" * source formatting * add missing testfile, update jni function * Undo commit of debug code * remove mislocated file * Fix h5repack test for handling of fapls and id close * Update h5diff test files usage text * HDFFV-11212 add new ref tests for JNI export dataset * src format update * Remove blank line typo * src format typo * long double requires %Lg * Another long double foramt specifer S.B. %Lg * issue with t128bit test * Windows issue with h5dump and type. * Fix review issues * refactor function nesting and fix error checks * format fixes * Remove untested functions and javadoc quiet comments * Restore TRY block. * Change string append errors to memory exception * revert to H5_JNI_FATAL_ERROR - support functions need work * Add assertion error for h5util functions * remove duplicate function * format fix * Revert HD function error handling * Update copyright comments
2021-02-26 05:12:57 +08:00
long btplist_id = HDF5Constants.H5I_INVALID_HID;
@Before
2019-09-06 03:35:33 +08:00
public void createFileAccess() throws NullPointerException, HDF5Exception
{
assertTrue("H5 open ids is 0", H5.getOpenIDCount() == 0);
System.out.print(testname.getMethodName());
try {
fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5Pfapl.createFileAccess: " + err);
}
assertTrue(fapl_id > 0);
try {
plapl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_ACCESS);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5Pfapl.createFileAccess: " + err);
}
assertTrue(plapl_id > 0);
try {
2022-04-20 02:08:09 +08:00
plist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
btplist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
2022-04-20 02:08:09 +08:00
dapl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_ACCESS);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5Pfapl.createFileAccess: " + err);
}
assertTrue(plist_id > 0);
assertTrue(btplist_id > 0);
assertTrue(dapl_id > 0);
}
@After
2019-09-06 03:35:33 +08:00
public void deleteFileAccess() throws HDF5LibraryException
{
if (fapl_id > 0)
2022-04-20 02:08:09 +08:00
try {
H5.H5Pclose(fapl_id);
}
catch (Exception ex) {
}
if (plapl_id > 0)
2022-04-20 02:08:09 +08:00
try {
H5.H5Pclose(plapl_id);
}
catch (Exception ex) {
}
if (dapl_id > 0)
2022-04-20 02:08:09 +08:00
try {
H5.H5Pclose(dapl_id);
}
catch (Exception ex) {
}
if (plist_id > 0)
2022-04-20 02:08:09 +08:00
try {
H5.H5Pclose(plist_id);
}
catch (Exception ex) {
}
if (btplist_id > 0)
2022-04-20 02:08:09 +08:00
try {
H5.H5Pclose(btplist_id);
}
catch (Exception ex) {
}
System.out.println();
}
@Test
2019-09-06 03:35:33 +08:00
public void testHDFS_fapl() throws Exception
{
if (HDF5Constants.H5FD_HDFS < 0)
throw new HDF5LibraryException("skip");
2022-04-20 02:08:09 +08:00
String nodename = "blues";
int nodeport = 12345;
String username = "sparticus";
String kerbcache = "/dev/null";
2022-04-20 02:08:09 +08:00
int streamsize = 1024;
2022-04-20 02:08:09 +08:00
final H5FD_hdfs_fapl_t config =
new H5FD_hdfs_fapl_t(nodename, nodeport, username, kerbcache, streamsize);
2019-09-06 03:35:33 +08:00
assertTrue("setting fapl should succeed", -1 < H5.H5Pset_fapl_hdfs(fapl_id, config));
2019-09-06 03:35:33 +08:00
assertEquals("driver types should match", HDF5Constants.H5FD_HDFS, H5.H5Pget_driver(fapl_id));
H5FD_hdfs_fapl_t copy = H5.H5Pget_fapl_hdfs(fapl_id);
2022-04-20 02:08:09 +08:00
assertEquals("fapl contents should match",
new H5FD_hdfs_fapl_t(nodename, nodeport, username, kerbcache, streamsize), copy);
}
@Test(expected = HDF5LibraryException.class)
2019-09-06 03:35:33 +08:00
public void testH5Pget_fapl_hdfs_invalid_fapl_id() throws Exception
{
if (HDF5Constants.H5FD_HDFS < 0)
throw new HDF5LibraryException("skip");
H5FD_hdfs_fapl_t fails = H5.H5Pget_fapl_hdfs(-1);
}
@Test(expected = HDF5LibraryException.class)
2019-09-06 03:35:33 +08:00
public void testH5Pget_fapl_hdfs_fapl_id_of_wrong_driver_type() throws Exception
{
if (HDF5Constants.H5FD_HDFS < 0)
throw new HDF5LibraryException("skip");
2022-04-20 02:08:09 +08:00
if (HDF5Constants.H5FD_SEC2 < 0)
throw new HDF5LibraryException("skip");
2022-04-20 02:08:09 +08:00
/* TODO: for now, test against a sec2 fapl only */
H5.H5Pset_fapl_sec2(fapl_id);
2019-09-06 03:35:33 +08:00
assertEquals("fapl_id was not set properly", HDF5Constants.H5FD_SEC2, H5.H5Pget_driver(fapl_id));
H5FD_hdfs_fapl_t fails = H5.H5Pget_fapl_hdfs(fapl_id);
}
}