builder.add(partition, new FetchRequest.PartitionData(position, FetchRequest.INVALID_LOG_START_OFFSET, this.fetchSize, Optional.empty()));
PartitionData nextData = next.get(topicPartition); if (nextData != null) { if (prevData.equals(nextData)) {
public FetchRequest(Struct struct) { super(struct); replicaId = struct.getInt(REPLICA_ID_KEY_NAME); maxWait = struct.getInt(MAX_WAIT_KEY_NAME); minBytes = struct.getInt(MIN_BYTES_KEY_NAME); fetchData = new HashMap<TopicPartition, PartitionData>(); for (Object topicResponseObj : struct.getArray(TOPICS_KEY_NAME)) { Struct topicResponse = (Struct) topicResponseObj; String topic = topicResponse.getString(TOPIC_KEY_NAME); for (Object partitionResponseObj : topicResponse.getArray(PARTITIONS_KEY_NAME)) { Struct partitionResponse = (Struct) partitionResponseObj; int partition = partitionResponse.getInt(PARTITION_KEY_NAME); long offset = partitionResponse.getLong(FETCH_OFFSET_KEY_NAME); int maxBytes = partitionResponse.getInt(MAX_BYTES_KEY_NAME); PartitionData partitionData = new PartitionData(offset, maxBytes); fetchData.put(new TopicPartition(topic, partition), partitionData); } } }
FetchSessionHandler.Builder builder = handler.newBuilder(); builder.add(new TopicPartition("foo", 0), new FetchRequest.PartitionData(0, 100, 200, Optional.empty())); builder.add(new TopicPartition("foo", 1), new FetchRequest.PartitionData(10, 110, 210, Optional.empty())); FetchSessionHandler.FetchRequestData data = builder.build(); assertMapsEqual(reqMap(new ReqEntry("foo", 0, 0, 100, 200), new FetchRequest.PartitionData(0, 100, 200, Optional.empty())); builder2.add(new TopicPartition("foo", 1), new FetchRequest.PartitionData(10, 120, 210, Optional.empty())); builder2.add(new TopicPartition("bar", 0), new FetchRequest.PartitionData(20, 200, 200, Optional.empty())); FetchSessionHandler.FetchRequestData data2 = builder2.build(); assertFalse(data2.metadata().isFull()); new FetchRequest.PartitionData(0, 100, 200, Optional.empty())); builder4.add(new TopicPartition("foo", 1), new FetchRequest.PartitionData(10, 120, 210, Optional.empty())); builder4.add(new TopicPartition("bar", 0), new FetchRequest.PartitionData(20, 200, 200, Optional.empty())); FetchSessionHandler.FetchRequestData data4 = builder4.build(); assertTrue(data4.metadata().isFull());
FetchSessionHandler.Builder builder = handler.newBuilder(); builder.add(new TopicPartition("foo", 0), new FetchRequest.PartitionData(0, 100, 200, Optional.empty())); builder.add(new TopicPartition("foo", 1), new FetchRequest.PartitionData(10, 110, 210, Optional.empty())); builder.add(new TopicPartition("bar", 0), new FetchRequest.PartitionData(20, 120, 220, Optional.empty())); FetchSessionHandler.FetchRequestData data = builder.build(); assertMapsEqual(reqMap(new ReqEntry("foo", 0, 0, 100, 200), new FetchRequest.PartitionData(10, 110, 210, Optional.empty())); FetchSessionHandler.FetchRequestData data2 = builder2.build(); assertFalse(data2.metadata().isFull()); FetchSessionHandler.Builder builder3 = handler.newBuilder(); builder3.add(new TopicPartition("foo", 0), new FetchRequest.PartitionData(0, 100, 200, Optional.empty())); FetchSessionHandler.FetchRequestData data3 = builder3.build(); assertTrue(data3.metadata().isFull());
PartitionData partitionData = new PartitionData(offset, logStartOffset, maxBytes, currentLeaderEpoch); fetchData.put(new TopicPartition(topic, partition), partitionData);
FetchSessionHandler.Builder builder = handler.newBuilder(); builder.add(new TopicPartition("foo", 0), new FetchRequest.PartitionData(0, 100, 200, Optional.empty())); builder.add(new TopicPartition("foo", 1), new FetchRequest.PartitionData(10, 110, 210, Optional.empty())); FetchSessionHandler.FetchRequestData data = builder.build(); assertMapsEqual(reqMap(new ReqEntry("foo", 0, 0, 100, 200), new FetchRequest.PartitionData(0, 100, 200, Optional.empty())); FetchSessionHandler.FetchRequestData data2 = builder2.build(); assertEquals(INVALID_SESSION_ID, data2.metadata().sessionId());
/** * Test that calling FetchSessionHandler#Builder#build twice fails. */ @Test public void testDoubleBuild() { FetchSessionHandler handler = new FetchSessionHandler(LOG_CONTEXT, 1); FetchSessionHandler.Builder builder = handler.newBuilder(); builder.add(new TopicPartition("foo", 0), new FetchRequest.PartitionData(0, 100, 200, Optional.empty())); builder.build(); try { builder.build(); fail("Expected calling build twice to fail."); } catch (Throwable t) { // expected } }
private FetchRequest createFetchRequest(int version, IsolationLevel isolationLevel) { LinkedHashMap<TopicPartition, FetchRequest.PartitionData> fetchData = new LinkedHashMap<>(); fetchData.put(new TopicPartition("test1", 0), new FetchRequest.PartitionData(100, 0L, 1000000, Optional.of(15))); fetchData.put(new TopicPartition("test2", 0), new FetchRequest.PartitionData(200, 0L, 1000000, Optional.of(25))); return FetchRequest.Builder.forConsumer(100, 100000, fetchData). isolationLevel(isolationLevel).setMaxBytes(1000).build((short) version); }
private FetchRequest createFetchRequest(int version) { LinkedHashMap<TopicPartition, FetchRequest.PartitionData> fetchData = new LinkedHashMap<>(); fetchData.put(new TopicPartition("test1", 0), new FetchRequest.PartitionData(100, 0L, 1000000, Optional.of(15))); fetchData.put(new TopicPartition("test2", 0), new FetchRequest.PartitionData(200, 0L, 1000000, Optional.of(25))); return FetchRequest.Builder.forConsumer(100, 100000, fetchData).setMaxBytes(1000).build((short) version); }
private FetchRequest createFetchRequest(int version, FetchMetadata metadata, List<TopicPartition> toForget) { LinkedHashMap<TopicPartition, FetchRequest.PartitionData> fetchData = new LinkedHashMap<>(); fetchData.put(new TopicPartition("test1", 0), new FetchRequest.PartitionData(100, 0L, 1000000, Optional.of(15))); fetchData.put(new TopicPartition("test2", 0), new FetchRequest.PartitionData(200, 0L, 1000000, Optional.of(25))); return FetchRequest.Builder.forConsumer(100, 100000, fetchData). metadata(metadata).setMaxBytes(1000).toForget(toForget).build((short) version); }
ReqEntry(String topic, int partition, long fetchOffset, long logStartOffset, int maxBytes) { this.part = new TopicPartition(topic, partition); this.data = new FetchRequest.PartitionData(fetchOffset, logStartOffset, maxBytes, Optional.empty()); } }