/** * Copyright (C) 2014-2016 LinkedIn Corp. (pinot-core@linkedin.com) * * Licensed 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 com.linkedin.pinot.request; import com.linkedin.pinot.common.exception.QueryException; import com.linkedin.pinot.common.response.broker.BrokerResponseNative; import com.linkedin.pinot.common.response.broker.QueryProcessingException; import java.io.IOException; import org.json.JSONException; import org.testng.Assert; import org.testng.annotations.Test; public class BrokerResponseNativeTest { @Test public void testEmptyResponse() throws JSONException, IOException { BrokerResponseNative expected = BrokerResponseNative.EMPTY_RESULT; String brokerString = expected.toJsonString(); BrokerResponseNative actual = BrokerResponseNative.fromJsonString(brokerString); Assert.assertEquals(actual.getNumDocsScanned(), expected.getNumDocsScanned()); Assert.assertEquals(actual.getTimeUsedMs(), expected.getTimeUsedMs()); Assert.assertEquals(actual.getAggregationResults(), expected.getAggregationResults()); Assert.assertEquals(actual.getSegmentStatistics().size(), expected.getSegmentStatistics().size()); } @Test public void testNullResponse() throws JSONException, IOException { BrokerResponseNative expected = BrokerResponseNative.NO_TABLE_RESULT; String brokerString = expected.toJsonString(); BrokerResponseNative actual = BrokerResponseNative.fromJsonString(brokerString); Assert.assertEquals(actual.getProcessingExceptions().get(0).getErrorCode(), QueryException.BROKER_RESOURCE_MISSING_ERROR.getErrorCode()); Assert.assertEquals(actual.getProcessingExceptions().get(0).getMessage(), QueryException.BROKER_RESOURCE_MISSING_ERROR.getMessage()); } @Test public void testMultipleExceptionsResponse() throws JSONException, IOException { BrokerResponseNative expected = BrokerResponseNative.NO_TABLE_RESULT; String errorMsgStr = "Some random string!"; QueryProcessingException processingException = new QueryProcessingException(400, errorMsgStr); expected.addToExceptions(processingException); String brokerString = expected.toJsonString(); // System.out.println(brokerString); BrokerResponseNative newBrokerResponse = BrokerResponseNative.fromJsonString(brokerString); Assert.assertEquals(newBrokerResponse.getProcessingExceptions().get(0).getErrorCode(), QueryException.BROKER_RESOURCE_MISSING_ERROR.getErrorCode()); Assert.assertEquals(newBrokerResponse.getProcessingExceptions().get(0).getMessage(), QueryException.BROKER_RESOURCE_MISSING_ERROR.getMessage()); // System.out.println(newBrokerResponse.getProcessingExceptions().get(1)); Assert.assertEquals(newBrokerResponse.getProcessingExceptions().get(1).getErrorCode(), 400); Assert.assertEquals(newBrokerResponse.getProcessingExceptions().get(1).getMessage(), errorMsgStr); } }