Search in sources :

Example 16 with RemoteTableDescriptor

use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.

the class TestRemoteTableDescriptor method doTestSerialize.

private void doTestSerialize(RateLimiter rateLimiter, CreditFunction readCredFn, CreditFunction writeCredFn) {
    String tableId = "1";
    RemoteTableDescriptor desc = new RemoteTableDescriptor(tableId).withReadFunction(createMockTableReadFunction()).withWriteFunction(createMockTableWriteFunction());
    if (rateLimiter != null) {
        desc.withRateLimiter(rateLimiter, readCredFn, writeCredFn);
        if (readCredFn == null) {
            desc.withReadRateLimiterDisabled();
        }
        if (writeCredFn == null) {
            desc.withWriteRateLimiterDisabled();
        }
    } else {
        desc.withReadRateLimit(100);
        desc.withWriteRateLimit(200);
    }
    Map<String, String> tableConfig = desc.toConfig(new MapConfig());
    assertExists(RemoteTableDescriptor.RATE_LIMITER, tableId, tableConfig);
    Assert.assertEquals(readCredFn != null, tableConfig.containsKey(JavaTableConfig.buildKey(tableId, RemoteTableDescriptor.READ_CREDIT_FN)));
    Assert.assertEquals(writeCredFn != null, tableConfig.containsKey(JavaTableConfig.buildKey(tableId, RemoteTableDescriptor.WRITE_CREDIT_FN)));
}
Also used : RemoteTableDescriptor(org.apache.samza.table.descriptors.RemoteTableDescriptor) Mockito.anyString(org.mockito.Mockito.anyString) MapConfig(org.apache.samza.config.MapConfig)

Example 17 with RemoteTableDescriptor

use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.

the class TestRemoteTableDescriptor method testTableRetryPolicyToConfig.

@Test
public void testTableRetryPolicyToConfig() {
    Map<String, String> tableConfig = new RemoteTableDescriptor("1").withReadFunction(createMockTableReadFunction()).withReadRetryPolicy(new TableRetryPolicy()).withRateLimiterDisabled().toConfig(new MapConfig());
    Assert.assertEquals(tableConfig.get("tables.1.io.read.retry.policy.TableRetryPolicy"), "{\"exponentialFactor\":0.0,\"backoffType\":\"NONE\",\"retryPredicate\":{}}");
}
Also used : TableRetryPolicy(org.apache.samza.table.retry.TableRetryPolicy) RemoteTableDescriptor(org.apache.samza.table.descriptors.RemoteTableDescriptor) Mockito.anyString(org.mockito.Mockito.anyString) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 18 with RemoteTableDescriptor

use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.

the class TestRemoteTableDescriptor method testValidateOnlyReadOrWriteFn.

@Test
public void testValidateOnlyReadOrWriteFn() {
    // Only read defined
    String tableId = "1";
    RemoteTableDescriptor desc = new RemoteTableDescriptor(tableId).withReadFunction(createMockTableReadFunction()).withReadRateLimiterDisabled();
    Map<String, String> tableConfig = desc.toConfig(new MapConfig());
    Assert.assertNotNull(tableConfig);
    // Only write defined
    String tableId2 = "2";
    RemoteTableDescriptor desc2 = new RemoteTableDescriptor(tableId2).withWriteFunction(createMockTableWriteFunction()).withWriteRateLimiterDisabled();
    tableConfig = desc2.toConfig(new MapConfig());
    Assert.assertNotNull(tableConfig);
    // Neither read or write defined (Failure case)
    String tableId3 = "3";
    RemoteTableDescriptor desc3 = new RemoteTableDescriptor(tableId3);
    try {
        desc3.toConfig(new MapConfig());
        Assert.fail("Should not allow neither readFn or writeFn defined");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof IllegalArgumentException);
        Assert.assertTrue(e.getMessage().contains("Must have one of TableReadFunction or TableWriteFunction"));
    }
}
Also used : RemoteTableDescriptor(org.apache.samza.table.descriptors.RemoteTableDescriptor) Mockito.anyString(org.mockito.Mockito.anyString) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 19 with RemoteTableDescriptor

use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.

the class TestRemoteTableDescriptor method testSerializeNullWriteFunction.

@Test
public void testSerializeNullWriteFunction() {
    String tableId = "1";
    RemoteTableDescriptor desc = new RemoteTableDescriptor(tableId).withReadFunction(createMockTableReadFunction()).withRateLimiterDisabled();
    Map<String, String> tableConfig = desc.toConfig(new MapConfig());
    assertExists(RemoteTableDescriptor.READ_FN, tableId, tableConfig);
    assertEquals(null, RemoteTableDescriptor.WRITE_FN, tableId, tableConfig);
}
Also used : RemoteTableDescriptor(org.apache.samza.table.descriptors.RemoteTableDescriptor) Mockito.anyString(org.mockito.Mockito.anyString) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Aggregations

RemoteTableDescriptor (org.apache.samza.table.descriptors.RemoteTableDescriptor)19 Test (org.junit.Test)17 MapConfig (org.apache.samza.config.MapConfig)15 TableReadFunction (org.apache.samza.table.remote.TableReadFunction)10 DelegatingSystemDescriptor (org.apache.samza.system.descriptors.DelegatingSystemDescriptor)9 Table (org.apache.samza.table.Table)9 TableRateLimiter (org.apache.samza.table.remote.TableRateLimiter)9 TableWriteFunction (org.apache.samza.table.remote.TableWriteFunction)9 RateLimiter (org.apache.samza.util.RateLimiter)9 Assert (org.junit.Assert)9 Mockito.anyString (org.mockito.Mockito.anyString)9 Duration (java.time.Duration)8 Arrays (java.util.Arrays)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SamzaException (org.apache.samza.SamzaException)8 StreamApplication (org.apache.samza.application.StreamApplication)8 KV (org.apache.samza.operators.KV)8 NoOpSerde (org.apache.samza.serializers.NoOpSerde)8 GenericInputDescriptor (org.apache.samza.system.descriptors.GenericInputDescriptor)8