You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2020/07/14 18:37:27 UTC

[accumulo] branch master updated: Added unit test to exercise bulk import range sanity check code #1618 (#1654)

This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new a9cf3a1  Added unit test to exercise bulk import range sanity check code #1618 (#1654)
a9cf3a1 is described below

commit a9cf3a10471fe344f2006a06c3ecdccdef682efa
Author: Keith Turner <kt...@apache.org>
AuthorDate: Tue Jul 14 14:37:16 2020 -0400

    Added unit test to exercise bulk import range sanity check code #1618 (#1654)
---
 .../core/clientImpl/bulk/BulkImportTest.java       | 106 +++++++++++++++++++++
 1 file changed, 106 insertions(+)

diff --git a/core/src/test/java/org/apache/accumulo/core/clientImpl/bulk/BulkImportTest.java b/core/src/test/java/org/apache/accumulo/core/clientImpl/bulk/BulkImportTest.java
new file mode 100644
index 0000000..b551148
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/clientImpl/bulk/BulkImportTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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.accumulo.core.clientImpl.bulk;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.accumulo.core.clientImpl.bulk.Bulk.FileInfo;
+import org.apache.accumulo.core.clientImpl.bulk.Bulk.Files;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.hadoop.io.Text;
+import org.junit.Test;
+
+public class BulkImportTest {
+
+  @Test
+  public void testMergeOverlappingSingleSplit() {
+    SortedMap<KeyExtent,Files> mappings = new TreeMap<>();
+
+    // simulate the tablet (m,s] splitting into (m,p] and (p,s] while files are being examined
+    addMapping(mappings, null, "m", "f0");
+    addMapping(mappings, "m", "s", "f1", "f2");
+    addMapping(mappings, "p", "s", "f3");
+    addMapping(mappings, "m", "p", "f4");
+    addMapping(mappings, "s", null, "f5");
+
+    var actual = BulkImport.mergeOverlapping(mappings);
+
+    SortedMap<KeyExtent,Files> expected = new TreeMap<>();
+    addMapping(expected, null, "m", "f0");
+    addMapping(expected, "m", "s", "f1", "f2", "f3", "f4");
+    addMapping(expected, "s", null, "f5");
+
+    assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testMergeOverlappingMultipleSplit() {
+    SortedMap<KeyExtent,Files> mappings = new TreeMap<>();
+
+    // simulate the tablet (m,s] splitting into (m,o],(o,p],(p,s] while files are being examined
+    addMapping(mappings, null, "m", "f0");
+    addMapping(mappings, "m", "s", "f1");
+    addMapping(mappings, "m", "o", "f2");
+    addMapping(mappings, "o", "p", "f3");
+    addMapping(mappings, "p", "s", "f4");
+    addMapping(mappings, "s", null, "f5");
+
+    var actual = BulkImport.mergeOverlapping(mappings);
+
+    SortedMap<KeyExtent,Files> expected = new TreeMap<>();
+    addMapping(expected, null, "m", "f0");
+    addMapping(expected, "m", "s", "f1", "f2", "f3", "f4");
+    addMapping(expected, "s", null, "f5");
+
+    assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testMergeOverlappingTabletsMergedAway() {
+    // simulate the tablets (m,p] and (p,s] being merged into (m,s] and that splitting into
+    // (m,q],(q,s] while files are being examined
+
+    SortedMap<KeyExtent,Files> mappings = new TreeMap<>();
+
+    addMapping(mappings, null, "m", "f0");
+    addMapping(mappings, "p", "s", "f1");
+    addMapping(mappings, "m", "p", "f2");
+    addMapping(mappings, "m", "s", "f3");
+    addMapping(mappings, "q", "s", "f4");
+    addMapping(mappings, "m", "q", "f5");
+    addMapping(mappings, "s", null, "f6");
+    assertThrows(RuntimeException.class, () -> BulkImport.mergeOverlapping(mappings));
+  }
+
+  private void addMapping(SortedMap<KeyExtent,Files> mappings, String prevRow, String endRow,
+      String... fileNames) {
+    KeyExtent ke = new KeyExtent(TableId.of("42"), endRow == null ? null : new Text(endRow),
+        prevRow == null ? null : new Text(prevRow));
+    Files files = new Files();
+    for (String name : fileNames) {
+      files.add(new FileInfo(name, 2, 2));
+    }
+    mappings.put(ke, files);
+  }
+}