Search in sources :

Example 1 with BoundedCostBackupRequests

use of com.linkedin.d2.BoundedCostBackupRequests in project rest.li by linkedin.

the class TestBackupRequestsStrategyFactory method testBoundedCostBackupRequestsWithDefaultsDeser.

@Test
public void testBoundedCostBackupRequestsWithDefaultsDeser() throws IOException {
    BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
    BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
    bcbr.setCost(3);
    brc.setOperation("BATCH_GET");
    brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
    String json = new JacksonDataCodec().mapToString(brc.data());
    @SuppressWarnings("unchecked") Map<String, Object> map = JacksonUtil.getObjectMapper().readValue(json, Map.class);
    BackupRequestsStrategy strategy = BackupRequestsStrategyFactory.tryCreate(map);
    assertNotNull(strategy);
    assertTrue(strategy instanceof BoundedCostBackupRequestsStrategy);
    BoundedCostBackupRequestsStrategy boundedCostStrategy = (BoundedCostBackupRequestsStrategy) strategy;
    assertEquals(boundedCostStrategy.getHistoryLength(), (int) bcbr.getHistoryLength());
    assertEquals(boundedCostStrategy.getMinBackupDelayNano(), (long) bcbr.getMinBackupDelayMs() * 1000L * 1000L);
    assertEquals(boundedCostStrategy.getRequiredHistory(), (int) bcbr.getRequiredHistoryLength());
    assertEquals(boundedCostStrategy.getPercent(), (double) bcbr.getCost());
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) BackupRequestsConfiguration(com.linkedin.d2.BackupRequestsConfiguration) BoundedCostBackupRequests(com.linkedin.d2.BoundedCostBackupRequests) Test(org.testng.annotations.Test)

Example 2 with BoundedCostBackupRequests

use of com.linkedin.d2.BoundedCostBackupRequests in project rest.li by linkedin.

the class TestBackupRequestsStrategyFactory method testBoundedCostBackupRequestsDeser.

@Test
public void testBoundedCostBackupRequestsDeser() throws IOException {
    BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
    BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
    bcbr.setCost(3);
    bcbr.setHistoryLength(4096);
    bcbr.setMaxBurst(16);
    bcbr.setMinBackupDelayMs(5);
    bcbr.setRequiredHistoryLength(65536);
    brc.setOperation("BATCH_GET");
    brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
    String json = new JacksonDataCodec().mapToString(brc.data());
    @SuppressWarnings("unchecked") Map<String, Object> map = JacksonUtil.getObjectMapper().readValue(json, Map.class);
    BackupRequestsStrategy strategy = BackupRequestsStrategyFactory.tryCreate(map);
    assertNotNull(strategy);
    assertTrue(strategy instanceof BoundedCostBackupRequestsStrategy);
    BoundedCostBackupRequestsStrategy boundedCostStrategy = (BoundedCostBackupRequestsStrategy) strategy;
    assertEquals(boundedCostStrategy.getHistoryLength(), (int) bcbr.getHistoryLength());
    assertEquals(boundedCostStrategy.getMinBackupDelayNano(), (long) bcbr.getMinBackupDelayMs() * 1000L * 1000L);
    assertEquals(boundedCostStrategy.getRequiredHistory(), (int) bcbr.getRequiredHistoryLength());
    assertEquals(boundedCostStrategy.getPercent(), (double) bcbr.getCost());
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) BackupRequestsConfiguration(com.linkedin.d2.BackupRequestsConfiguration) BoundedCostBackupRequests(com.linkedin.d2.BoundedCostBackupRequests) Test(org.testng.annotations.Test)

Example 3 with BoundedCostBackupRequests

use of com.linkedin.d2.BoundedCostBackupRequests in project rest.li by linkedin.

the class BackupRequestsConverterTest method testBackupRequestsConverter.

@Test
public void testBackupRequestsConverter() {
    BackupRequestsConfigurationArray configArray = new BackupRequestsConfigurationArray();
    BackupRequestsConfiguration config = new BackupRequestsConfiguration();
    config.setOperation("myOperation");
    BoundedCostBackupRequests boundedCostBackupRequests = new BoundedCostBackupRequests();
    boundedCostBackupRequests.setCost(5);
    boundedCostBackupRequests.setHistoryLength(4096);
    boundedCostBackupRequests.setMaxBurst(45);
    boundedCostBackupRequests.setMinBackupDelayMs(50);
    boundedCostBackupRequests.setRequiredHistoryLength(456);
    config.setStrategy(Strategy.create(boundedCostBackupRequests));
    // round trip conversion test
    Assert.assertEquals(BackupRequestsConverter.toConfig(BackupRequestsConverter.toProperties(configArray)), configArray);
}
Also used : BackupRequestsConfiguration(com.linkedin.d2.BackupRequestsConfiguration) BoundedCostBackupRequests(com.linkedin.d2.BoundedCostBackupRequests) BackupRequestsConfigurationArray(com.linkedin.d2.BackupRequestsConfigurationArray) Test(org.testng.annotations.Test)

Example 4 with BoundedCostBackupRequests

use of com.linkedin.d2.BoundedCostBackupRequests in project rest.li by linkedin.

the class TestBackupRequestsClient method createBackupRequestsConfiguration.

@SuppressWarnings("unchecked")
private final Map<String, Object> createBackupRequestsConfiguration(int cost, String operation) throws JsonParseException, JsonMappingException, IOException {
    BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
    BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
    bcbr.setCost(cost);
    brc.setOperation(operation);
    brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
    String json = new JacksonDataCodec().mapToString(brc.data());
    return JacksonUtil.getObjectMapper().readValue(json, Map.class);
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) BackupRequestsConfiguration(com.linkedin.d2.BackupRequestsConfiguration) BoundedCostBackupRequests(com.linkedin.d2.BoundedCostBackupRequests) ByteString(com.linkedin.data.ByteString)

Aggregations

BackupRequestsConfiguration (com.linkedin.d2.BackupRequestsConfiguration)4 BoundedCostBackupRequests (com.linkedin.d2.BoundedCostBackupRequests)4 JacksonDataCodec (com.linkedin.data.codec.JacksonDataCodec)3 Test (org.testng.annotations.Test)3 BackupRequestsConfigurationArray (com.linkedin.d2.BackupRequestsConfigurationArray)1 ByteString (com.linkedin.data.ByteString)1