vlsi commented on a change in pull request #1591: [CALCITE-3510] Implement  
Redis adapter
URL: https://github.com/apache/calcite/pull/1591#discussion_r357565455
 
 

 ##########
 File path: 
redis/src/test/java/org/apache/calcite/adapter/redis/RedisAdapterCaseBase.java
 ##########
 @@ -0,0 +1,176 @@
+/*
+ * 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.calcite.adapter.redis;
+
+import org.apache.calcite.config.CalciteSystemProperty;
+import org.apache.calcite.test.CalciteAssert;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+import redis.clients.jedis.Protocol;
+
+/**
+ * Tests for the {@code org.apache.calcite.adapter.redis} package.
+ */
+public class RedisAdapterCaseBase extends RedisDataCaseBase {
+  /**
+   * URL of the "redis-zips" model.
+   */
+  private URL url =
+      RedisAdapterCaseBase.class.getResource("/redis-mix-model.json");
+
+  private String targetFile;
+  private boolean isSupport = true;
+
+  @SuppressWarnings("unchecked")
+  private static final Map<String, Integer> TABLE_MAPS = new HashMap(15);
+
+  static {
+    TABLE_MAPS.put("raw_01", 1);
+    TABLE_MAPS.put("raw_02", 2);
+    TABLE_MAPS.put("raw_03", 2);
+    TABLE_MAPS.put("raw_04", 2);
+    TABLE_MAPS.put("raw_05", 2);
+    TABLE_MAPS.put("csv_01", 1);
+    TABLE_MAPS.put("csv_02", 2);
+    TABLE_MAPS.put("csv_03", 2);
+    TABLE_MAPS.put("csv_04", 2);
+    TABLE_MAPS.put("csv_05", 2);
+    TABLE_MAPS.put("json_01", 1);
+    TABLE_MAPS.put("json_02", 2);
+    TABLE_MAPS.put("json_03", 2);
+    TABLE_MAPS.put("json_04", 2);
+    TABLE_MAPS.put("json_05", 2);
+  }
+
+  @BeforeEach
+  @Override public void makeData() {
+    super.makeData();
+    setRedisJsonFile();
+  }
+
+  /**
+   * Whether to run this test.
+   */
+  private boolean enabled() {
+    return CalciteSystemProperty.TEST_REDIS.value();
+  }
+
+  /**
+   * Creates a query against a data set given by a map.
+   */
+  private CalciteAssert.AssertQuery sql(String sql, URL url) {
+    return CalciteAssert.that()
+        .enable(enabled())
+        .withModel(url)
+        .query(sql);
+  }
+
+  /**
+   * Creates a query against the {@link #url} data set.
+   */
+  private CalciteAssert.AssertQuery sql(String sql) {
+    return sql(sql, url);
+  }
+
+  private void setRedisJsonFile() {
+    try {
+      String strResult;
+      ObjectMapper objMapper = new ObjectMapper();
+      objMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
+          .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
+          .configure(JsonParser.Feature.ALLOW_COMMENTS, true);
+      File file = new File(this.url.getFile());
+      if (file.exists()) {
+        JsonNode rootNode = objMapper.readTree(new File(this.url.getFile()));
+        strResult = 
rootNode.toString().replace(Integer.toString(Protocol.DEFAULT_PORT),
+            Integer.toString(PORT));
+        String tmpPath = System.getProperty("java.io.tmpdir");
+        targetFile = tmpPath + "/" + System.currentTimeMillis() + ".json";
+        try (OutputStream fos = new FileOutputStream(targetFile, false);
+             Writer writer = new OutputStreamWriter(fos, 
StandardCharsets.UTF_8)) {
+          writer.write(strResult);
+          writer.flush();
+        } catch (IOException e) {
+          e.printStackTrace();
+        }
+        url = new File(targetFile).toURI().toURL();
+      } else {
+        isSupport = false;
+      }
+    } catch (Exception e) {
+      isSupport = false;
+      e.printStackTrace();
+    }
+  }
+
+  @Test
+  public void testRedisBySql() {
+    if (!isSupport) {
+      return;
+    }
 
 Review comment:
   What does that mean? Does that mean the test would silently be marked as 
"passed test" while in practice it would be ignored/skipped?
   
   Please write tests in such a way so "successful" test in logs means the test 
was really performing some verifications.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to