Search in sources :

Example 6 with BoundedCostBackupRequestsStrategy

use of com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy 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)

Aggregations

Test (org.testng.annotations.Test)5 BoundedCostBackupRequestsStrategy (com.linkedin.d2.backuprequests.BoundedCostBackupRequestsStrategy)4 BackupRequestsConfiguration (com.linkedin.d2.BackupRequestsConfiguration)2 BoundedCostBackupRequests (com.linkedin.d2.BoundedCostBackupRequests)2 JacksonDataCodec (com.linkedin.data.codec.JacksonDataCodec)2