@Test public void testSplitTask() { LineDelimitedDataSubmissionTask task = new LineDelimitedDataSubmissionTask(null, null, null, null, "graphite_v2", ReportableEntityType.POINT, "2878", ImmutableList.of("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"), null); List<LineDelimitedDataSubmissionTask> split; split = task.splitTask(11, 4); assertEquals(1, split.size()); assertSame(split.get(0), task); split = task.splitTask(10, 11); assertEquals(2, split.size()); assertArrayEquals(new String[] {"A", "B", "C", "D", "E", "F"}, split.get(0).payload.toArray()); assertArrayEquals(new String[] {"G", "H", "I", "J", "K"}, split.get(1).payload.toArray()); split = task.splitTask(10, 6); assertEquals(2, split.size()); assertArrayEquals(new String[] {"A", "B", "C", "D", "E", "F"}, split.get(0).payload.toArray()); assertArrayEquals(new String[] {"G", "H", "I", "J", "K"}, split.get(1).payload.toArray()); split = task.splitTask(10, 5); assertEquals(3, split.size()); assertArrayEquals(new String[] {"A", "B", "C", "D", "E"}, split.get(0).payload.toArray()); assertArrayEquals(new String[] {"F", "G", "H", "I", "J"}, split.get(1).payload.toArray()); assertArrayEquals(new String[] {"K"}, split.get(2).payload.toArray()); split = task.splitTask(7, 4); assertEquals(3, split.size()); assertArrayEquals(new String[] {"A", "B", "C", "D"}, split.get(0).payload.toArray()); assertArrayEquals(new String[] {"E", "F", "G", "H"}, split.get(1).payload.toArray()); assertArrayEquals(new String[] {"I", "J", "K"}, split.get(2).payload.toArray()); split = task.splitTask(7, 3); assertEquals(4, split.size()); assertArrayEquals(new String[] {"A", "B", "C"}, split.get(0).payload.toArray()); assertArrayEquals(new String[] {"D", "E", "F"}, split.get(1).payload.toArray()); assertArrayEquals(new String[] {"G", "H", "I"}, split.get(2).payload.toArray()); assertArrayEquals(new String[] {"J", "K"}, split.get(3).payload.toArray()); split = task.splitTask(7, 2); assertEquals(6, split.size()); assertArrayEquals(new String[] {"A", "B"}, split.get(0).payload.toArray()); assertArrayEquals(new String[] {"C", "D"}, split.get(1).payload.toArray()); assertArrayEquals(new String[] {"E", "F"}, split.get(2).payload.toArray()); assertArrayEquals(new String[] {"G", "H"}, split.get(3).payload.toArray()); assertArrayEquals(new String[] {"I", "J"}, split.get(4).payload.toArray()); assertArrayEquals(new String[] {"K"}, split.get(5).payload.toArray()); }
@Override public List<LineDelimitedDataSubmissionTask> splitTask(int minSplitSize, int maxSplitSize) { if (payload.size() > Math.max(1, minSplitSize)) { List<LineDelimitedDataSubmissionTask> result = new ArrayList<>(); int stride = Math.min(maxSplitSize, (int) Math.ceil((float) payload.size() / 2.0)); int endingIndex = 0; for (int startingIndex = 0; endingIndex < payload.size() - 1; startingIndex += stride) { endingIndex = Math.min(payload.size(), startingIndex + stride) - 1; result.add(new LineDelimitedDataSubmissionTask(api, proxyId, properties, backlog, format, getEntityType(), handle, payload.subList(startingIndex, endingIndex + 1), timeProvider)); } return result; } return ImmutableList.of(this); }
LineDelimitedDataSubmissionTask extends AbstractDataSubmissionTask<LineDelimitedDataSubmissionTask> { @Override public List<LineDelimitedDataSubmissionTask> splitTask(int minSplitSize, int maxSplitSize) { if (payload.size() > Math.max(1, minSplitSize)) { List<LineDelimitedDataSubmissionTask> result = new ArrayList<>(); int stride = Math.min(maxSplitSize, (int) Math.ceil((float) payload.size() / 2.0)); int endingIndex = 0; for (int startingIndex = 0; endingIndex < payload.size() - 1; startingIndex += stride) { endingIndex = Math.min(payload.size(), startingIndex + stride) - 1; result.add(new LineDelimitedDataSubmissionTask(api, proxyId, properties, backlog, format, getEntityType(), handle, payload.subList(startingIndex, endingIndex + 1), timeProvider)); } return result; } return ImmutableList.of(this); } }
LineDelimitedDataSubmissionTask extends AbstractDataSubmissionTask<LineDelimitedDataSubmissionTask> { @Override public List<LineDelimitedDataSubmissionTask> splitTask(int minSplitSize, int maxSplitSize) { if (payload.size() > Math.max(1, minSplitSize)) { List<LineDelimitedDataSubmissionTask> result = new ArrayList<>(); int stride = Math.min(maxSplitSize, (int) Math.ceil((float) payload.size() / 2.0)); int endingIndex = 0; for (int startingIndex = 0; endingIndex < payload.size() - 1; startingIndex += stride) { endingIndex = Math.min(payload.size(), startingIndex + stride) - 1; result.add(new LineDelimitedDataSubmissionTask(api, proxyId, properties, backlog, format, getEntityType(), handle, payload.subList(startingIndex, endingIndex + 1), timeProvider)); } return result; } return ImmutableList.of(this); } @SuppressWarnings("unused")  LineDelimitedDataSubmissionTask();  LineDelimitedDataSubmissionTask(ProxyV2API api, UUID proxyId, EntityProperties properties,
                                         TaskQueue<LineDelimitedDataSubmissionTask> backlog,
                                         String format, ReportableEntityType entityType,
                                         String handle, @Nonnull List<String> payload,
                                         @Nullable Supplier<Long> timeProvider); }
LineDelimitedDataSubmissionTask extends AbstractDataSubmissionTask<LineDelimitedDataSubmissionTask> { @Override public List<LineDelimitedDataSubmissionTask> splitTask(int minSplitSize, int maxSplitSize) { if (payload.size() > Math.max(1, minSplitSize)) { List<LineDelimitedDataSubmissionTask> result = new ArrayList<>(); int stride = Math.min(maxSplitSize, (int) Math.ceil((float) payload.size() / 2.0)); int endingIndex = 0; for (int startingIndex = 0; endingIndex < payload.size() - 1; startingIndex += stride) { endingIndex = Math.min(payload.size(), startingIndex + stride) - 1; result.add(new LineDelimitedDataSubmissionTask(api, proxyId, properties, backlog, format, getEntityType(), handle, payload.subList(startingIndex, endingIndex + 1), timeProvider)); } return result; } return ImmutableList.of(this); } @SuppressWarnings("unused")  LineDelimitedDataSubmissionTask();  LineDelimitedDataSubmissionTask(ProxyV2API api, UUID proxyId, EntityProperties properties,
                                         TaskQueue<LineDelimitedDataSubmissionTask> backlog,
                                         String format, ReportableEntityType entityType,
                                         String handle, @Nonnull List<String> payload,
                                         @Nullable Supplier<Long> timeProvider); @Override int weight(); @Override List<LineDelimitedDataSubmissionTask> splitTask(int minSplitSize, int maxSplitSize); List<String> payload(); void injectMembers(ProxyV2API api, UUID proxyId, EntityProperties properties,
                            TaskQueue<LineDelimitedDataSubmissionTask> backlog); }
LineDelimitedDataSubmissionTask extends AbstractDataSubmissionTask<LineDelimitedDataSubmissionTask> { @Override public List<LineDelimitedDataSubmissionTask> splitTask(int minSplitSize, int maxSplitSize) { if (payload.size() > Math.max(1, minSplitSize)) { List<LineDelimitedDataSubmissionTask> result = new ArrayList<>(); int stride = Math.min(maxSplitSize, (int) Math.ceil((float) payload.size() / 2.0)); int endingIndex = 0; for (int startingIndex = 0; endingIndex < payload.size() - 1; startingIndex += stride) { endingIndex = Math.min(payload.size(), startingIndex + stride) - 1; result.add(new LineDelimitedDataSubmissionTask(api, proxyId, properties, backlog, format, getEntityType(), handle, payload.subList(startingIndex, endingIndex + 1), timeProvider)); } return result; } return ImmutableList.of(this); } @SuppressWarnings("unused")  LineDelimitedDataSubmissionTask();  LineDelimitedDataSubmissionTask(ProxyV2API api, UUID proxyId, EntityProperties properties,
                                         TaskQueue<LineDelimitedDataSubmissionTask> backlog,
                                         String format, ReportableEntityType entityType,
                                         String handle, @Nonnull List<String> payload,
                                         @Nullable Supplier<Long> timeProvider); @Override int weight(); @Override List<LineDelimitedDataSubmissionTask> splitTask(int minSplitSize, int maxSplitSize); List<String> payload(); void injectMembers(ProxyV2API api, UUID proxyId, EntityProperties properties,
                            TaskQueue<LineDelimitedDataSubmissionTask> backlog);  }