use of org.apache.pulsar.common.functions.WindowConfig in project pulsar by apache.
the class WindowFunctionExecutorTest method testPrepareLateTupleStreamWithoutTs.
@Test
public void testPrepareLateTupleStreamWithoutTs() throws Exception {
context = mock(Context.class);
doReturn("test-function").when(context).getFunctionName();
doReturn("test-namespace").when(context).getNamespace();
doReturn("test-tenant").when(context).getTenant();
doReturn(Collections.singleton("test-source-topic")).when(context).getInputTopics();
doReturn("test-sink-topic").when(context).getOutputTopic();
WindowConfig windowConfig = new WindowConfig();
windowConfig.setWindowLengthDurationMs(20L);
windowConfig.setSlidingIntervalDurationMs(10L);
windowConfig.setLateDataTopic("$late");
windowConfig.setMaxLagMs(5L);
windowConfig.setWatermarkEmitIntervalMs(10L);
windowConfig.setActualWindowFunctionClassName(TestFunction.class.getName());
doReturn(Optional.of(new Gson().fromJson(new Gson().toJson(windowConfig), Map.class))).when(context).getUserConfigValue(WindowConfig.WINDOW_CONFIG_KEY);
try {
testWindowedPulsarFunction.process(10L, context);
fail();
} catch (IllegalArgumentException e) {
assertEquals(e.getMessage(), "Late data topic can be defined only when specifying a " + "timestamp extractor class");
}
}
use of org.apache.pulsar.common.functions.WindowConfig in project pulsar by apache.
the class WindowFunctionExecutorTest method testExecuteWithWrongJavaWindowFunctionType.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testExecuteWithWrongJavaWindowFunctionType() throws Exception {
WindowConfig windowConfig = new WindowConfig();
windowConfig.setActualWindowFunctionClassName(TestWrongFunction.class.getName());
doReturn(Optional.of(new Gson().fromJson(new Gson().toJson(windowConfig), Map.class))).when(context).getUserConfigValue(WindowConfig.WINDOW_CONFIG_KEY);
testWindowedPulsarFunction.process(10L, context);
}
use of org.apache.pulsar.common.functions.WindowConfig in project pulsar by yahoo.
the class WindowConfigUtilsTest method testSettingSlidingCountWindow.
@Test
public void testSettingSlidingCountWindow() throws Exception {
final Object[][] args = new Object[][] { { -1, 10 }, { 10, -1 }, { 0, 10 }, { 10, 0 }, { 0, 0 }, { -1, -1 }, { 5, 10 }, { 1, 1 }, { 10, 5 }, { 100, 10 }, { 100, 100 }, { 200, 100 }, { 500, 100 }, { null, null }, { null, 1 }, { 1, null }, { null, -1 }, { -1, null } };
for (Object[] arg : args) {
Object arg0 = arg[0];
Object arg1 = arg[1];
try {
Integer windowLengthCount = null;
if (arg0 != null) {
windowLengthCount = (Integer) arg0;
}
Integer slidingIntervalCount = null;
if (arg1 != null) {
slidingIntervalCount = (Integer) arg1;
}
WindowConfig windowConfig = new WindowConfig();
windowConfig.setWindowLengthCount(windowLengthCount);
windowConfig.setSlidingIntervalCount(slidingIntervalCount);
WindowConfigUtils.validate(windowConfig);
if (arg0 == null) {
fail(String.format("Window length cannot be null -- " + "windowLengthCount: %s slidingIntervalCount: %s", arg0, arg1));
}
if ((Integer) arg0 <= 0) {
fail(String.format("Window length cannot be zero or less -- " + "windowLengthCount: %s slidingIntervalCount: %s", arg0, arg1));
}
if (arg1 != null && (Integer) arg1 <= 0) {
fail(String.format("Sliding interval length cannot be zero or less -- " + "windowLengthCount: %s slidingIntervalCount: %s", arg0, arg1));
}
} catch (IllegalArgumentException e) {
if (arg0 != null && arg1 != null && (Integer) arg0 > 0 && (Integer) arg1 > 0) {
fail(String.format("Exception: %s thrown on valid input -- windowLengthCount: %s " + "slidingIntervalCount: %s", e.getMessage(), arg0, arg1));
}
}
}
}
use of org.apache.pulsar.common.functions.WindowConfig in project pulsar by yahoo.
the class WindowConfigUtilsTest method testSettingTumblingTimeWindow.
@Test
public void testSettingTumblingTimeWindow() throws Exception {
final Object[] args = new Object[] { -1L, 0L, 1L, 2L, 5L, 10L, null };
for (Object arg : args) {
Object arg0 = arg;
try {
Long windowLengthDuration = null;
if (arg0 != null) {
windowLengthDuration = (Long) arg0;
}
WindowConfig windowConfig = new WindowConfig();
windowConfig.setWindowLengthDurationMs(windowLengthDuration);
WindowConfigUtils.validate(windowConfig);
if (arg0 == null) {
fail(String.format("Window count duration cannot be null -- windowLengthDuration: %s", arg0));
}
if ((Long) arg0 <= 0) {
fail(String.format("Window length cannot be zero or less -- windowLengthDuration: %s", arg0));
}
} catch (IllegalArgumentException e) {
if (arg0 != null && (Long) arg0 > 0) {
fail(String.format("Exception: %s thrown on valid input -- windowLengthDuration: %s", e.getMessage(), arg0));
}
}
}
}
use of org.apache.pulsar.common.functions.WindowConfig in project pulsar by yahoo.
the class WindowConfigUtilsTest method testSettingTumblingCountWindow.
@Test
public void testSettingTumblingCountWindow() throws Exception {
final Object[] args = new Object[] { -1, 0, 1, 2, 5, 10, null };
for (Object arg : args) {
Object arg0 = arg;
try {
Integer windowLengthCount = null;
if (arg0 != null) {
windowLengthCount = (Integer) arg0;
}
WindowConfig windowConfig = new WindowConfig();
windowConfig.setWindowLengthCount(windowLengthCount);
WindowConfigUtils.validate(windowConfig);
if (arg0 == null) {
fail(String.format("Window length cannot be null -- windowLengthCount: %s", arg0));
}
if ((Integer) arg0 <= 0) {
fail(String.format("Window length cannot be zero or less -- windowLengthCount: %s", arg0));
}
} catch (IllegalArgumentException e) {
if (arg0 != null && (Integer) arg0 > 0) {
fail(String.format("Exception: %s thrown on valid input -- windowLengthCount: %s", e.getMessage(), arg0));
}
}
}
}
Aggregations