Search in sources :

Example 6 with ProtocolVersion

use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.

the class TestClientBuilders method checkBasicRequest.

private void checkBasicRequest(Request<?> request, URIDetails expectedURIDetails, ResourceMethod expectedMethod, CollectionRequest<?> expectedInput, BatchRequest<?> expectedBatchInput, Map<String, String> expectedHeaders, List<Object> expectedStreamingDataSources) {
    final ProtocolVersion version = expectedURIDetails.getProtocolVersion();
    checkBasicRequest(request, expectedURIDetails, expectedMethod, expectedInput, expectedHeaders, expectedStreamingDataSources);
    if (request.getMethod() == ResourceMethod.BATCH_UPDATE || request.getMethod() == ResourceMethod.BATCH_PARTIAL_UPDATE) {
        // check the conversion
        checkInputForBatchUpdateAndPatch(request, expectedBatchInput, version);
    }
}
Also used : ProtocolVersion(com.linkedin.restli.common.ProtocolVersion)

Example 7 with ProtocolVersion

use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.

the class TestVersionNegotiation method getProtocolVersionClient.

@DataProvider(name = "data")
public Object[][] getProtocolVersionClient() {
    ProtocolVersion lessThanDefaultVersion = new ProtocolVersion(0, 5, 0);
    ProtocolVersion betweenDefaultAndLatestVersion = new ProtocolVersion(2, 5, 0);
    ProtocolVersion greaterThanLatestVersion = new ProtocolVersion(3, 5, 0);
    ProtocolVersion greaterThanNextVersion = new ProtocolVersion(3, 5, 0);
    return new Object[][] { // baseline protocol "advertised" + graceful option => baseline protocol version
    { _BASELINE_VERSION, ProtocolVersionOption.USE_LATEST_IF_AVAILABLE, _BASELINE_VERSION }, // latest protocol "advertised" + force latest option => latest protocol version
    { _LATEST_VERSION, ProtocolVersionOption.FORCE_USE_LATEST, _LATEST_VERSION }, // baseline protocol "advertised" + force latest option => latest protocol version 
    { _BASELINE_VERSION, ProtocolVersionOption.FORCE_USE_LATEST, _LATEST_VERSION }, // latest protocol "advertised" + graceful option => latest protocol version 
    { _LATEST_VERSION, ProtocolVersionOption.USE_LATEST_IF_AVAILABLE, _LATEST_VERSION }, // use the version "advertised" by the server as it is less than the latest protocol version
    { betweenDefaultAndLatestVersion, ProtocolVersionOption.USE_LATEST_IF_AVAILABLE, betweenDefaultAndLatestVersion }, // servers should support it as well.
    { greaterThanNextVersion, ProtocolVersionOption.USE_LATEST_IF_AVAILABLE, _LATEST_VERSION }, // force latest option => latest protocol version 
    { betweenDefaultAndLatestVersion, ProtocolVersionOption.FORCE_USE_LATEST, _LATEST_VERSION }, // force latest option => latest protocol version 
    { lessThanDefaultVersion, ProtocolVersionOption.FORCE_USE_LATEST, _LATEST_VERSION }, // if servers "advertise" a version that is greater than the latest version we always use the latest version
    { greaterThanLatestVersion, ProtocolVersionOption.FORCE_USE_LATEST, _LATEST_VERSION }, // if servers "advertise" a version that is greater than the latest version we always use the latest version
    { greaterThanLatestVersion, ProtocolVersionOption.USE_LATEST_IF_AVAILABLE, _LATEST_VERSION }, // default version "advertised" + force next => next
    { _BASELINE_VERSION, ProtocolVersionOption.FORCE_USE_NEXT, _NEXT_VERSION }, // latest version "advertised" + force next => next
    { _LATEST_VERSION, ProtocolVersionOption.FORCE_USE_NEXT, _NEXT_VERSION }, // next "advertised" + force next => next
    { _NEXT_VERSION, ProtocolVersionOption.FORCE_USE_NEXT, _NEXT_VERSION }, // version between default and latest "advertised" + force next => next
    { betweenDefaultAndLatestVersion, ProtocolVersionOption.FORCE_USE_NEXT, _NEXT_VERSION }, // version greater than latest "advertised" + force next => next
    { greaterThanLatestVersion, ProtocolVersionOption.FORCE_USE_NEXT, _NEXT_VERSION }, // default version "advertised" + force next => next
    { _BASELINE_VERSION, ProtocolVersionOption.FORCE_USE_PREVIOUS, _PREV_VERSION }, // latest version "advertised" + force next => next
    { _LATEST_VERSION, ProtocolVersionOption.FORCE_USE_PREVIOUS, _PREV_VERSION }, // next "advertised" + force next => next
    { _NEXT_VERSION, ProtocolVersionOption.FORCE_USE_PREVIOUS, _PREV_VERSION }, // version between default and latest "advertised" + force next => next
    { betweenDefaultAndLatestVersion, ProtocolVersionOption.FORCE_USE_PREVIOUS, _PREV_VERSION }, // version greater than latest "advertised" + force next => next
    { greaterThanLatestVersion, ProtocolVersionOption.FORCE_USE_PREVIOUS, _PREV_VERSION } };
}
Also used : ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) DataProvider(org.testng.annotations.DataProvider)

Example 8 with ProtocolVersion

use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.

the class TestVersionNegotiation method testAnnouncedVersionLessThanPrev.

@Test
public void testAnnouncedVersionLessThanPrev() {
    try {
        RestClient.getProtocolVersion(_BASELINE_VERSION, _PREV_VERSION, _LATEST_VERSION, _NEXT_VERSION, new ProtocolVersion(0, 0, 0), ProtocolVersionOption.USE_LATEST_IF_AVAILABLE, false);
        Assert.fail("Expected a RuntimeException as the announced version is less than the earliest supported version!");
    } catch (RuntimeException e) {
        Assert.assertTrue(e.getMessage().contains("Announced version is less than the earliest supported version!"));
    }
}
Also used : ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) Test(org.testng.annotations.Test)

Example 9 with ProtocolVersion

use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.

the class TestVersionNegotiation method testAnnouncedVersionWithVersionPercentages.

@Test(dataProvider = "versionTestVariations")
public void testAnnouncedVersionWithVersionPercentages(ProtocolVersion versionInput, String versionPercentageInput, ProtocolVersion expectedAnnouncedVersion) {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(RestConstants.RESTLI_PROTOCOL_VERSION_PROPERTY, versionInput);
    properties.put(RestConstants.RESTLI_PROTOCOL_VERSION_PERCENTAGE_PROPERTY, versionPercentageInput);
    ProtocolVersion announcedVersion = RestClient.getAnnouncedVersion(properties);
    Assert.assertEquals(announcedVersion, expectedAnnouncedVersion);
}
Also used : HashMap(java.util.HashMap) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) Test(org.testng.annotations.Test)

Example 10 with ProtocolVersion

use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.

the class TestVersionNegotiation method testForceUseNextVersionOverride.

@Test(dataProvider = "testForceUseNextVersionOverrideData")
public void testForceUseNextVersionOverride(ProtocolVersionOption protocolVersionOption, ProtocolVersion expectedProtocolVersion, boolean forceUseOverrideSystemProperty) {
    ProtocolVersion announcedVersion = new ProtocolVersion("2.0.0");
    ProtocolVersion actualProtocolVersion = RestClient.getProtocolVersion(_BASELINE_VERSION, _PREV_VERSION, _LATEST_VERSION, _NEXT_VERSION, announcedVersion, protocolVersionOption, forceUseOverrideSystemProperty);
    Assert.assertEquals(actualProtocolVersion, expectedProtocolVersion);
}
Also used : ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) Test(org.testng.annotations.Test)

Aggregations

ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)35 DataMap (com.linkedin.data.DataMap)12 Test (org.testng.annotations.Test)8 CompoundKey (com.linkedin.restli.common.CompoundKey)7 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)7 URI (java.net.URI)7 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)5 HashMap (java.util.HashMap)5 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)4 ResourceMethod (com.linkedin.restli.common.ResourceMethod)4 ByteString (com.linkedin.data.ByteString)3 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)3 ErrorResponse (com.linkedin.restli.common.ErrorResponse)3 IdResponse (com.linkedin.restli.common.IdResponse)3 AnyRecord (com.linkedin.restli.internal.server.methods.AnyRecord)3 HttpCookie (java.net.HttpCookie)3 HashSet (java.util.HashSet)3 RecordTemplate (com.linkedin.data.template.RecordTemplate)2 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)2 Foo (com.linkedin.pegasus.generator.examples.Foo)2