Fix ASTERIXDB-1776

The source of the issue was a deprecated method that failed when two
IODevices share a common prefix in their absolute path

Change-Id: Iba7837b433ce57f99e2c547e8bd1fb0bfc5a31df
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1489
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-common-test/pom.xml b/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-common-test/pom.xml
index 98a441d..1b5910b 100644
--- a/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-common-test/pom.xml
+++ b/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-common-test/pom.xml
@@ -64,5 +64,9 @@
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
   </dependencies>
 </project>
\ No newline at end of file
diff --git a/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-common-test/src/test/java/org/apache/hyracks/storage/common/IOManagerPathTest.java b/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-common-test/src/test/java/org/apache/hyracks/storage/common/IOManagerPathTest.java
new file mode 100644
index 0000000..512a187
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-tests/hyracks-storage-common-test/src/test/java/org/apache/hyracks/storage/common/IOManagerPathTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.hyracks.storage.common;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.FileReference;
+import org.apache.hyracks.api.io.IODeviceHandle;
+import org.apache.hyracks.control.nc.io.IOManager;
+import org.junit.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+public class IOManagerPathTest {
+    @Test
+    public void testPrefixNames() throws HyracksDataException {
+        IODeviceHandle shorter = new IODeviceHandle(new File("/tmp/tst/1"), "storage");
+        IODeviceHandle longer = new IODeviceHandle(new File("/tmp/tst/11"), "storage");
+        IOManager ioManager = new IOManager(Arrays.asList(new IODeviceHandle[] { shorter, longer }));
+        FileReference f = ioManager.resolveAbsolutePath("/tmp/tst/11/storage/Foo_idx_foo/my_btree");
+        Assert.assertEquals("/tmp/tst/11/storage/Foo_idx_foo/my_btree", f.getAbsolutePath());
+    }
+
+    @Test(expected = HyracksDataException.class)
+    public void testDuplicates() throws HyracksDataException {
+        IODeviceHandle first = new IODeviceHandle(new File("/tmp/tst/1"), "storage");
+        IODeviceHandle second = new IODeviceHandle(new File("/tmp/tst/1"), "storage");
+        IOManager ioManager = new IOManager(Arrays.asList(new IODeviceHandle[] { first, second }));
+    }
+
+    @After
+    @Before
+    public void cleanup() throws IOException {
+        FileUtils.deleteDirectory(new File("/tmp/tst/"));
+    }
+
+}