You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/02/23 00:57:53 UTC

[GitHub] [pinot] xiangfu0 commented on a change in pull request #8233: Add Flink Pinot connector

xiangfu0 commented on a change in pull request #8233:
URL: https://github.com/apache/pinot/pull/8233#discussion_r812483234



##########
File path: pinot-connectors/pinot-flink-connector/src/test/java/org/apache/pinot/connector/flink/http/PinotControllerClientTest.java
##########
@@ -0,0 +1,168 @@
+/**
+ * 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.pinot.connector.flink.http;
+
+import com.google.common.collect.Lists;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import org.apache.commons.io.IOUtils;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.testng.annotations.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+
+
+public class PinotControllerClientTest {
+
+  private static final String TABLE_NAME = "demand";
+
+  @Test
+  public void testGetPinotControllerInstancesFromController()
+      throws Exception {
+    Client client = mock(Client.class);
+    WebTarget target = mock(WebTarget.class);
+    Invocation.Builder builder = mock(Invocation.Builder.class);
+    Response response = mock(Response.class);
+    MultivaluedMap<String, Object> headers = getRequestHeadersToPinot();
+    String expectedFullURL = "http://localhost:9000/instances";
+    final Map<String, Object> resEntity =
+        JsonUtils.stringToObject(fixture("fixtures/pinotControllerInstances.json"), Map.class);
+
+    when(client.target(expectedFullURL)).thenReturn(target);
+    when(target.request()).thenReturn(builder);
+    when(builder.headers(headers)).thenReturn(builder);
+    when(builder.get()).thenReturn(response);
+    when(response.getStatus()).thenReturn(200);
+    when(response.getEntity()).thenReturn(resEntity);
+    when(response.readEntity(Map.class)).thenReturn(resEntity);
+
+    PinotControllerClient controllerClient = new PinotControllerClient();
+    controllerClient.setHttpClient(client);
+    List<String> instances = controllerClient.getControllerInstances(new MultivaluedHashMap<>());
+    assertEquals(Lists.newArrayList("pinot-prod02:5983"), instances);
+
+    verify(client, times(1)).target(expectedFullURL);
+    verify(target, times(1)).request();
+    verify(builder, times(1)).headers(headers);
+    verify(builder, times(1)).get();
+  }
+
+  @Test
+  public void testGetPinotSchemaStrFromController()
+      throws Exception {
+    Client client = mock(Client.class);
+    WebTarget target = mock(WebTarget.class);
+    Invocation.Builder builder = mock(Invocation.Builder.class);
+    Response response = mock(Response.class);
+    MultivaluedMap<String, Object> headers = getRequestHeadersToPinot();
+    String expectedFullURL = "http://localhost:9000/schemas/demand";
+    final Map<String, Object> resEntity =
+        JsonUtils.stringToObject(fixture("fixtures/pinotTableSchema.json"), Map.class);
+
+    when(client.target(expectedFullURL)).thenReturn(target);
+    when(target.request()).thenReturn(builder);
+    when(builder.headers(headers)).thenReturn(builder);
+    when(builder.get()).thenReturn(response);
+    when(response.getStatus()).thenReturn(200);
+    when(response.getEntity()).thenReturn(resEntity);
+    when(response.readEntity(Map.class)).thenReturn(resEntity);
+
+    PinotControllerClient controllerClient = new PinotControllerClient();
+    controllerClient.setHttpClient(client);
+    String schemaStrFromController =
+        controllerClient.getSchemaStrFromController(TABLE_NAME, new MultivaluedHashMap<>());
+    assertEquals(
+        JsonUtils.objectToString(JsonUtils.stringToObject(fixture("fixtures/pinotTableSchema.json"), Map.class)),
+        schemaStrFromController);
+
+    verify(client, times(1)).target(expectedFullURL);
+    verify(target, times(1)).request();
+    verify(builder, times(1)).headers(headers);
+    verify(builder, times(1)).get();
+  }
+
+  @Test
+  public void testGetPinotConfigStrFromController()
+      throws Exception {
+    Client client = mock(Client.class);
+    WebTarget target = mock(WebTarget.class);
+    Invocation.Builder builder = mock(Invocation.Builder.class);
+    Response response = mock(Response.class);
+    MultivaluedMap<String, Object> headers = getRequestHeadersToPinot();
+    String expectedFullURL = "http://localhost:9000/tables/demand?type=realtime";
+    final Map<String, Object> resEntity = new HashMap<>() {

Review comment:
       This seems not compilable for jdk8:
   ```
   Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:testCompile (default-testCompile) on project flink-pinot-sink: Compilation failure
   Error:  /home/runner/work/pinot/pinot/pinot-connectors/pinot-flink-connector/src/test/java/org/apache/pinot/connector/flink/http/PinotControllerClientTest.java:[124,53] error: cannot infer type arguments for HashMap<K,V>
   Error:    reason: cannot use '<>' with anonymous inner classes
   Error:    where K,V are type-variables:
   Error:      K extends Object declared in class HashMap
   Error:      V extends Object declared in class HashMap
   Error:  -> [Help 1]
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org