-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RB=820373 BUG=SI-3070 G=si-dev R=mnchen,kvidhani,axu A=mnchen,sihde,kvidhani,axu
- Loading branch information
Jun Chen
committed
Sep 26, 2016
1 parent
382f189
commit 0ba4a56
Showing
8 changed files
with
214 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ent/src/test/java/com/linkedin/restli/internal/client/TestBatchUpdateResponseDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,63 @@ | |||
/* | |||
Copyright (c) 2014 LinkedIn Corp. | |||
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.restli.internal.client; | |||
|
|||
|
|||
import java.io.IOException; | |||
import java.lang.reflect.InvocationTargetException; | |||
import java.util.Collections; | |||
import java.util.Map; | |||
|
|||
import org.testng.Assert; | |||
import org.testng.annotations.DataProvider; | |||
import org.testng.annotations.Test; | |||
|
|||
import com.linkedin.restli.client.response.BatchKVResponse; | |||
import com.linkedin.restli.common.CompoundKey; | |||
import com.linkedin.restli.common.ErrorResponse; | |||
import com.linkedin.restli.common.ProtocolVersion; | |||
import com.linkedin.restli.common.TypeSpec; | |||
import com.linkedin.restli.common.UpdateStatus; | |||
import com.linkedin.restli.internal.common.AllProtocolVersions; | |||
import com.linkedin.restli.internal.common.TestConstants; | |||
|
|||
|
|||
/** | |||
* @author Jun Chen | |||
*/ | |||
public class TestBatchUpdateResponseDecoder | |||
{ | |||
@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchEntityResponseDataProvider") | |||
private static Object[][] batchEntityResponseDataProvider() | |||
{ | |||
return new Object[][] { | |||
{ AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion() }, | |||
{ AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion() }, | |||
}; | |||
} | |||
|
|||
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchEntityResponseDataProvider") | |||
public void testDecodingWithEmptyDataMap(ProtocolVersion protocolVersion) | |||
throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException | |||
{ | |||
final BatchUpdateResponseDecoder<String> decoder = | |||
new BatchUpdateResponseDecoder<String>(new TypeSpec<String>(String.class), Collections.<String, CompoundKey.TypeInfo>emptyMap(), null); | |||
|
|||
final BatchKVResponse<String, UpdateStatus> response = decoder.wrapResponse(null, Collections.<String, String>emptyMap(), protocolVersion); | |||
Assert.assertNull(response); | |||
} | |||
} |
103 changes: 103 additions & 0 deletions
103
restli-int-test/src/test/java/com/linkedin/restli/client/TestResponseDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,103 @@ | |||
/* | |||
Copyright (c) 2012 LinkedIn Corp. | |||
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.restli.client; | |||
|
|||
|
|||
import com.linkedin.common.callback.CallbackAdapter; | |||
import com.linkedin.restli.examples.RestLiIntegrationTest; | |||
import com.linkedin.restli.examples.TestConstants; | |||
import com.linkedin.restli.examples.greetings.api.Message; | |||
import com.linkedin.restli.examples.greetings.client.StringKeysRequestBuilders; | |||
|
|||
import java.util.HashSet; | |||
import java.util.Set; | |||
|
|||
import org.testng.Assert; | |||
import org.testng.annotations.AfterClass; | |||
import org.testng.annotations.BeforeClass; | |||
import org.testng.annotations.DataProvider; | |||
import org.testng.annotations.Test; | |||
|
|||
|
|||
/** | |||
* Tests for client response decoders. | |||
* | |||
* @author Jun Chen | |||
*/ | |||
public class TestResponseDecoder extends RestLiIntegrationTest | |||
{ | |||
/* header size (in KBs) that likely exceed server request limit and will cause container exception. */ | |||
private static int SERVER_HEADER_OVERLOAD_SIZE = 50; | |||
|
|||
@BeforeClass | |||
public void initClass() throws Exception | |||
{ | |||
super.init(); | |||
} | |||
|
|||
@AfterClass | |||
public void shutDown() throws Exception | |||
{ | |||
super.shutdown(); | |||
} | |||
|
|||
/** | |||
* This test tests 2 things in combo here: | |||
* 1) BatchEntityResponseDecoder could be invoked in some cases to try to decode a empty response dataMap when | |||
* non-rest.li server error returns, in this test, we simulate that by passing a over-size URL param | |||
* {@link com.linkedin.restli.internal.client.ExceptionUtil#exceptionForThrowable(java.lang.Throwable, com.linkedin.restli.internal.client.RestResponseDecoder)} | |||
* | |||
* 2) CallbackAdapter and its subclasses could have error while its dealing with error itself, this test make sure it | |||
* pass the 'new' error to its inner callback's onError method. | |||
* {@link CallbackAdapter#onError(java.lang.Throwable)} | |||
*/ | |||
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "dataProvider") | |||
public void testNonRestliServerErrorHandling(RestliRequestOptions requestOptions) throws Exception | |||
{ | |||
Set<String> keys = new HashSet<String>(); | |||
keys.add(createDataSize(SERVER_HEADER_OVERLOAD_SIZE)); | |||
BatchGetEntityRequest<String, Message> req = new StringKeysRequestBuilders(requestOptions).batchGet().ids(keys).build(); | |||
ResponseFuture batchKVResponseResponseFuture = getClient().sendRequest(req); | |||
try { | |||
batchKVResponseResponseFuture.getResponse(); | |||
Assert.fail("Exception should have thrown before this point!"); | |||
} catch (Throwable e) { | |||
Assert.assertTrue(e instanceof RestLiResponseException); | |||
Assert.assertEquals(((RestLiResponseException) e).getStatus(), 414); | |||
} | |||
} | |||
|
|||
@DataProvider(name = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "dataProvider") | |||
private static Object[][] dataProvider() | |||
{ | |||
return new Object[][] { | |||
{ RestliRequestOptions.DEFAULT_OPTIONS }, | |||
{ TestConstants.FORCE_USE_NEXT_OPTIONS } | |||
}; | |||
} | |||
|
|||
/** | |||
* Creates a string of size @msgSize in KB. | |||
*/ | |||
private static String createDataSize(int msgSize) { | |||
msgSize = msgSize / 2 * 1024; | |||
StringBuilder sb = new StringBuilder(msgSize); | |||
for (int i = 0; i < msgSize; i++) | |||
sb.append('a'); | |||
return sb.toString(); | |||
} | |||
} |