jineshparakh commented on code in PR #18515:
URL: https://github.com/apache/pinot/pull/18515#discussion_r3271608492


##########
pinot-broker/src/test/java/org/apache/pinot/broker/api/resources/PinotClientRequestTest.java:
##########
@@ -274,10 +325,103 @@ public void testGetQueryFingerprintWithInvalidSql() 
throws Exception {
     when(request.getRequestURL()).thenReturn(new StringBuilder());
 
     String requestJson = "{\"sql\": \"INVALID SQL QUERY\"}";
-    Response response = _pinotClientRequest.getQueryFingerprint(requestJson, 
request, null);
+    try {
+      _pinotClientRequest.getQueryFingerprint(requestJson, request, null);
+      Assert.fail("Expected BadRequestException");
+    } catch (WebApplicationException wae) {
+      assertEquals(wae.getResponse().getStatus(), 
Response.Status.BAD_REQUEST.getStatusCode(),
+          "Invalid SQL query should return BAD_REQUEST status");
+    }
+    
verify(_brokerMetrics).addMeteredGlobalValue(BrokerMeter.BAD_REQUEST_EXCEPTIONS,
 1L);
+    verify(_brokerMetrics, 
never()).addMeteredGlobalValue(BrokerMeter.UNCAUGHT_POST_EXCEPTIONS, 1L);
+  }
+
+  @Test
+  public void testProcessSqlQueryPostMissingSql() {
+    AsyncResponse asyncResponse = mock(AsyncResponse.class);
+    Request request = mock(Request.class);
+    when(request.getRequestURL()).thenReturn(new StringBuilder());
+
+    _pinotClientRequest.processSqlQueryPost("{}", asyncResponse, false, 0, 
request, null);
+
+    ArgumentCaptor<WebApplicationException> captor = 
ArgumentCaptor.forClass(WebApplicationException.class);
+    verify(asyncResponse).resume(captor.capture());
+    assertEquals(captor.getValue().getResponse().getStatus(), 
Response.Status.BAD_REQUEST.getStatusCode());
+    
verify(_brokerMetrics).addMeteredGlobalValue(BrokerMeter.BAD_REQUEST_EXCEPTIONS,
 1L);
+    verify(_brokerMetrics, 
never()).addMeteredGlobalValue(BrokerMeter.UNCAUGHT_POST_EXCEPTIONS, 1L);
+  }
+
+  @Test
+  public void testProcessSqlQueryPostInvalidJson() {
+    AsyncResponse asyncResponse = mock(AsyncResponse.class);
+    Request request = mock(Request.class);
+    when(request.getRequestURL()).thenReturn(new StringBuilder());
+
+    _pinotClientRequest.processSqlQueryPost("{bad json", asyncResponse, false, 
0, request, null);
+
+    ArgumentCaptor<WebApplicationException> captor = 
ArgumentCaptor.forClass(WebApplicationException.class);
+    verify(asyncResponse).resume(captor.capture());
+    assertEquals(captor.getValue().getResponse().getStatus(), 
Response.Status.BAD_REQUEST.getStatusCode());
+    
verify(_brokerMetrics).addMeteredGlobalValue(BrokerMeter.BAD_REQUEST_EXCEPTIONS,
 1L);
+    verify(_brokerMetrics, 
never()).addMeteredGlobalValue(BrokerMeter.UNCAUGHT_POST_EXCEPTIONS, 1L);
+  }
+
+  @Test
+  public void testGetQueryFingerprintMissingSql() {
+    Request request = mock(Request.class);
+    when(request.getRequestURL()).thenReturn(new StringBuilder());
+
+    try {
+      _pinotClientRequest.getQueryFingerprint("{}", request, null);
+      Assert.fail("Expected BadRequestException");
+    } catch (WebApplicationException wae) {
+      assertEquals(wae.getResponse().getStatus(), 
Response.Status.BAD_REQUEST.getStatusCode());
+    }
+    
verify(_brokerMetrics).addMeteredGlobalValue(BrokerMeter.BAD_REQUEST_EXCEPTIONS,
 1L);
+    verify(_brokerMetrics, 
never()).addMeteredGlobalValue(BrokerMeter.UNCAUGHT_POST_EXCEPTIONS, 1L);
+  }
+
+  @Test
+  public void testGetQueryFingerprintInvalidJson() {
+    Request request = mock(Request.class);
+    when(request.getRequestURL()).thenReturn(new StringBuilder());
+
+    try {
+      _pinotClientRequest.getQueryFingerprint("{bad json", request, null);
+      Assert.fail("Expected BadRequestException");
+    } catch (WebApplicationException wae) {
+      assertEquals(wae.getResponse().getStatus(), 
Response.Status.BAD_REQUEST.getStatusCode());
+    }
+    
verify(_brokerMetrics).addMeteredGlobalValue(BrokerMeter.BAD_REQUEST_EXCEPTIONS,
 1L);
+    verify(_brokerMetrics, 
never()).addMeteredGlobalValue(BrokerMeter.UNCAUGHT_POST_EXCEPTIONS, 1L);
+  }
+
+  @Test
+  public void testCancelQueryWithInvalidId() {
+    try {
+      _pinotClientRequest.cancelQuery("not-a-number", false, 3000, false);

Review Comment:
   Done



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to