nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [nifi] granthenke commented on a change in pull request #3732: NIFI-6662: Adding Kudu Lookup Service
Date Fri, 13 Sep 2019 21:00:12 GMT
granthenke commented on a change in pull request #3732: NIFI-6662: Adding Kudu Lookup Service
URL: https://github.com/apache/nifi/pull/3732#discussion_r324365782
 
 

 ##########
 File path: nifi-nar-bundles/nifi-kudu-bundle/nifi-kudu-controller-service/src/test/java/org/apache/nifi/controller/kudu/TestKuduLookupService.java
 ##########
 @@ -0,0 +1,222 @@
+/*
+ * 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.nifi.controller.kudu;
+
+import org.apache.kudu.ColumnSchema;
+import org.apache.kudu.Schema;
+import org.apache.kudu.Type;
+import org.apache.kudu.client.CreateTableOptions;
+import org.apache.kudu.client.Insert;
+import org.apache.kudu.client.KuduClient;
+import org.apache.kudu.client.KuduSession;
+import org.apache.kudu.client.KuduTable;
+import org.apache.kudu.client.PartialRow;
+import org.apache.kudu.test.KuduTestHarness;
+import org.apache.nifi.lookup.LookupFailureException;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.serialization.record.Record;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+public class TestKuduLookupService {
+
+    // The KuduTestHarness automatically starts and stops a real Kudu cluster
+    // when each test is run. Kudu persists its on-disk state in a temporary
+    // directory under a location defined by the environment variable TEST_TMPDIR
+    // if set, or under /tmp otherwise. That cluster data is deleted on
+    // successful exit of the test. The cluster output is logged through slf4j.
+    @Rule
+    public KuduTestHarness harness = new KuduTestHarness();
+    private TestRunner testRunner;
+    private long nowMillis = System.currentTimeMillis();
+    private KuduLookupService kuduLookupService;
+
+    public static class SampleProcessor extends AbstractProcessor {
+        @Override
+        public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException
{
+        }
+    }
+
+    @Before
+    public void init() throws Exception {
+        testRunner = TestRunners.newTestRunner(SampleProcessor.class);
+        testRunner.setValidateExpressionUsage(false);
+        final String tableName = "table1";
+
+        KuduClient client =  harness.getClient();
+        List<ColumnSchema> columns = new ArrayList<>();
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("string", Type.STRING).key(true).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("binary", Type.BINARY).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("bool", Type.BOOL).build());
+        //columns.add(new ColumnSchema.ColumnSchemaBuilder("decimal", Type.DECIMAL).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("double", Type.DOUBLE).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("float", Type.FLOAT).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("int8", Type.INT8).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("int16", Type.INT16).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("int32", Type.INT32).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("int64", Type.INT64).build());
+        columns.add(new ColumnSchema.ColumnSchemaBuilder("unixtime_micros", Type.UNIXTIME_MICROS).build());
+        Schema schema = new Schema(columns);
+
+        CreateTableOptions opts = new CreateTableOptions().setRangePartitionColumns(Collections.singletonList("string"));
+        client.createTable(tableName, schema, opts);
+
+        KuduTable table = client.openTable(tableName);
+        KuduSession session = client.newSession();
+
+        Insert insert = table.newInsert();
+        PartialRow row = insert.getRow();
+        row.addString("string", "string1");
+        row.addBinary("binary", "binary1".getBytes());
+        row.addBoolean("bool",true);
+        //row.addDecimal("decimal", new BigDecimal(0.1));
+        row.addDouble("double",0.2);
+        row.addFloat("float",0.3f);
+        row.addByte("int8", (byte) 1);
+        row.addShort("int16", (short) 2);
+        row.addInt("int32",3);
+        row.addLong("int64",4L);
+        row.addTimestamp("unixtime_micros", new Timestamp(nowMillis));
+        session.apply(insert);
+
+        insert = table.newInsert();
+        row = insert.getRow();
+        row.addString("string", "string2");
+        row.addBinary("binary", "binary2".getBytes());
+        row.addBoolean("bool",false);
+        //row.addDecimal("decimal", new BigDecimal(1.1));
+        row.addDouble("double",1.2);
+        row.addFloat("float",1.3f);
+        row.addByte("int8", (byte) 11);
+        row.addShort("int16", (short) 12);
+        row.addInt("int32",13);
+        row.addLong("int64",14L);
+        row.addTimestamp("unixtime_micros", new Timestamp(nowMillis+(1000L * 60 * 60 * 24
* 365))); //+ 1 year
+        session.apply(insert);
+
+        session.close();
+
+        kuduLookupService = new KuduLookupService();
+        testRunner.addControllerService("kuduLookupService", kuduLookupService);
+        testRunner.setProperty(kuduLookupService, KuduLookupService.KUDU_MASTERS, "unused:7150");
+        testRunner.setProperty(kuduLookupService, KuduLookupService.TABLE_NAME, tableName);
+        kuduLookupService.kuduClient = client;
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void invalid_key() throws LookupFailureException {
+        testRunner.setProperty(kuduLookupService, KuduLookupService.RETURN_COLUMNS, "*");
+
+        testRunner.enableControllerService(kuduLookupService);
+
+        Map<String,Object> map = new HashMap<>();
+        map.put("invalid", "invalid key");
+        kuduLookupService.lookup(map);
+    }
+    @Test
+    public void row_not_found() throws LookupFailureException {
+        testRunner.setProperty(kuduLookupService, KuduLookupService.RETURN_COLUMNS, "*");
+
+        testRunner.enableControllerService(kuduLookupService);
+
+        Map<String,Object> map = new HashMap<>();
+        map.put("string", "key not found");
+        Optional<Record> result = kuduLookupService.lookup(map);
+        assertFalse(result.isPresent());
+    }
+
+    @Test
+    public void single_key() throws LookupFailureException {
+        testRunner.setProperty(kuduLookupService, KuduLookupService.RETURN_COLUMNS, "*");
+
+        testRunner.enableControllerService(kuduLookupService);
+
+        Map<String,Object> map = new HashMap<>();
+        map.put("string", "string1");
+        Record result = kuduLookupService.lookup(map).get();
+        validateRow1(result);
+    }
+    @Test
+    public void multi_key() throws LookupFailureException {
 
 Review comment:
   In some ways this is still single key because the underlying Kudu table primary key is
just "string". Should the lookup service be required to match the primary key to guarantee
only 1 row can be returned? If it doesn't match the primary key, should we enforce that only
1 row is returned at lookup time? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message