Search in sources :

Example 1 with CapacityThroughputInformation

use of com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation in project cloudant-java-sdk by IBM.

the class Cloudant method putCapacityThroughputConfiguration.

/**
 * Update the target provisioned throughput capacity.
 *
 * Sets the target provisioned throughput capacity for an IBM Cloudant instance. When target capacity is changed, the
 * current capacity asynchronously changes to meet the target capacity.
 *
 * @param putCapacityThroughputConfigurationOptions the {@link PutCapacityThroughputConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link CapacityThroughputInformation}
 */
public ServiceCall<CapacityThroughputInformation> putCapacityThroughputConfiguration(PutCapacityThroughputConfigurationOptions putCapacityThroughputConfigurationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putCapacityThroughputConfigurationOptions, "putCapacityThroughputConfigurationOptions cannot be null");
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/capacity/throughput"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putCapacityThroughputConfiguration");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("blocks", putCapacityThroughputConfigurationOptions.blocks());
    builder.bodyJson(contentJson);
    ResponseConverter<CapacityThroughputInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CapacityThroughputInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : CapacityThroughputInformation(com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject)

Example 2 with CapacityThroughputInformation

use of com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation in project cloudant-java-sdk by IBM.

the class CloudantTest method testGetCapacityThroughputInformationWOptions.

@Test
public void testGetCapacityThroughputInformationWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"current\": {\"throughput\": {\"blocks\": 0, \"query\": 0, \"read\": 0, \"write\": 0}}, \"target\": {\"throughput\": {\"blocks\": 0, \"query\": 0, \"read\": 0, \"write\": 0}}}";
    String getCapacityThroughputInformationPath = "/_api/v2/user/capacity/throughput";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetCapacityThroughputInformationOptions model
    GetCapacityThroughputInformationOptions getCapacityThroughputInformationOptionsModel = new GetCapacityThroughputInformationOptions();
    // Invoke operation with valid options model (positive test)
    Response<CapacityThroughputInformation> response = cloudantService.getCapacityThroughputInformation(getCapacityThroughputInformationOptionsModel).execute();
    assertNotNull(response);
    CapacityThroughputInformation responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getCapacityThroughputInformationPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CapacityThroughputInformation(com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation) GetCapacityThroughputInformationOptions(com.ibm.cloud.cloudant.v1.model.GetCapacityThroughputInformationOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with CapacityThroughputInformation

use of com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation in project cloudant-java-sdk by IBM.

the class CloudantTest method testPutCapacityThroughputConfigurationWOptions.

@Test
public void testPutCapacityThroughputConfigurationWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"current\": {\"throughput\": {\"blocks\": 0, \"query\": 0, \"read\": 0, \"write\": 0}}, \"target\": {\"throughput\": {\"blocks\": 0, \"query\": 0, \"read\": 0, \"write\": 0}}}";
    String putCapacityThroughputConfigurationPath = "/_api/v2/user/capacity/throughput";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PutCapacityThroughputConfigurationOptions model
    PutCapacityThroughputConfigurationOptions putCapacityThroughputConfigurationOptionsModel = new PutCapacityThroughputConfigurationOptions.Builder().blocks(Long.valueOf("0")).build();
    // Invoke operation with valid options model (positive test)
    Response<CapacityThroughputInformation> response = cloudantService.putCapacityThroughputConfiguration(putCapacityThroughputConfigurationOptionsModel).execute();
    assertNotNull(response);
    CapacityThroughputInformation responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, putCapacityThroughputConfigurationPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) PutCapacityThroughputConfigurationOptions(com.ibm.cloud.cloudant.v1.model.PutCapacityThroughputConfigurationOptions) CapacityThroughputInformation(com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with CapacityThroughputInformation

use of com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation in project cloudant-java-sdk by IBM.

the class Cloudant method getCapacityThroughputInformation.

/**
 * Retrieve provisioned throughput capacity information.
 *
 * View the amount of provisioned throughput capacity that is allocated to an IBM Cloudant instance and what is the
 * target provisioned throughput capacity.
 *
 * @param getCapacityThroughputInformationOptions the {@link GetCapacityThroughputInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link CapacityThroughputInformation}
 */
public ServiceCall<CapacityThroughputInformation> getCapacityThroughputInformation(GetCapacityThroughputInformationOptions getCapacityThroughputInformationOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/capacity/throughput"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getCapacityThroughputInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<CapacityThroughputInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CapacityThroughputInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : CapacityThroughputInformation(com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Example 5 with CapacityThroughputInformation

use of com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation in project cloudant-java-sdk by IBM.

the class CapacityThroughputInformationTest method testCapacityThroughputInformation.

@Test
public void testCapacityThroughputInformation() throws Throwable {
    CapacityThroughputInformation capacityThroughputInformationModel = new CapacityThroughputInformation();
    assertNull(capacityThroughputInformationModel.getCurrent());
    assertNull(capacityThroughputInformationModel.getTarget());
}
Also used : CapacityThroughputInformation(com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation) Test(org.testng.annotations.Test)

Aggregations

CapacityThroughputInformation (com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation)5 Test (org.testng.annotations.Test)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 JsonObject (com.google.gson.JsonObject)1 GetCapacityThroughputInformationOptions (com.ibm.cloud.cloudant.v1.model.GetCapacityThroughputInformationOptions)1 PutCapacityThroughputConfigurationOptions (com.ibm.cloud.cloudant.v1.model.PutCapacityThroughputConfigurationOptions)1