org.apache.kafka.common.protocol.Errors Java Examples

The following examples show how to use org.apache.kafka.common.protocol.Errors. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroupCoordinator.java    From kop with Apache License 2.0 6 votes vote down vote up
public KeyValue<Errors, List<GroupOverview>> handleListGroups() {
    if (!isActive.get()) {
        return new KeyValue<>(Errors.COORDINATOR_NOT_AVAILABLE, new ArrayList<>());
    } else {
        Errors errors;
        if (groupManager.isLoading()) {
            errors = Errors.COORDINATOR_LOAD_IN_PROGRESS;
        } else {
            errors = Errors.NONE;
        }
        List<GroupOverview> overviews = new ArrayList<>();
        groupManager.currentGroups().forEach(group -> overviews.add(group.overview()));
        return new KeyValue<>(
            errors,
            overviews
        );
    }
}
 
Example #2
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 6 votes vote down vote up
@Test
public void testListGroupsIncludesRebalancingGroups() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, newProtocols()
    );
    assertEquals(Errors.NONE, joinGroupResult.getError());

    KeyValue<Errors, List<GroupOverview>> groups = groupCoordinator.handleListGroups();
    assertEquals(Errors.NONE, groups.getKey());
    assertEquals(1, groups.getValue().size());
    assertEquals(
        new GroupOverview("groupId", "consumer"),
        groups.getValue().get(0)
    );
}
 
Example #3
Source File: KafkaApisTest.java    From kop with Apache License 2.0 6 votes vote down vote up
@Test(timeOut = 20000, enabled = false)
// https://github.com/streamnative/kop/issues/51
public void testGetOffsetsForUnknownTopic() throws Exception {
    String topicName = "kopTestGetOffsetsForUnknownTopic";

    TopicPartition tp = new TopicPartition(topicName, 0);
    Map<TopicPartition, Long> targetTimes = Maps.newHashMap();
    targetTimes.put(tp, ListOffsetRequest.LATEST_TIMESTAMP);

    ListOffsetRequest.Builder builder = ListOffsetRequest.Builder
        .forConsumer(false, IsolationLevel.READ_UNCOMMITTED)
        .setTargetTimes(targetTimes);

    KafkaHeaderAndRequest request = buildRequest(builder);
    CompletableFuture<AbstractResponse> responseFuture = new CompletableFuture<>();
    kafkaRequestHandler
        .handleListOffsetRequest(request, responseFuture);

    AbstractResponse response = responseFuture.get();
    ListOffsetResponse listOffsetResponse = (ListOffsetResponse) response;
    assertEquals(listOffsetResponse.responseData().get(tp).error,
        Errors.UNKNOWN_TOPIC_OR_PARTITION);
}
 
Example #4
Source File: KafkaApisTest.java    From kop with Apache License 2.0 6 votes vote down vote up
@Test(timeOut = 20000, enabled = false)
// https://github.com/streamnative/kop/issues/51
public void testOffsetCommitWithInvalidPartition() throws Exception {
    String topicName = "kopOffsetCommitWithInvalidPartition";

    CompletableFuture<AbstractResponse> invalidResponse1 = new CompletableFuture<>();
    // invalid partition id -1;
    checkInvalidPartition(invalidResponse1, topicName, -1);
    AbstractResponse response1 = invalidResponse1.get();
    TopicPartition topicPartition1 = new TopicPartition(topicName, -1);
    assertEquals(((OffsetCommitResponse) response1).responseData().get(topicPartition1),
        Errors.UNKNOWN_TOPIC_OR_PARTITION);

    // invalid partition id 1.
    CompletableFuture<AbstractResponse> invalidResponse2 = new CompletableFuture<>();
    checkInvalidPartition(invalidResponse2, topicName, 1);
    TopicPartition topicPartition2 = new TopicPartition(topicName, 1);
    AbstractResponse response2 = invalidResponse2.get();
    assertEquals(((OffsetCommitResponse) response2).responseData().get(topicPartition2),
        Errors.UNKNOWN_TOPIC_OR_PARTITION);
}
 
Example #5
Source File: KafkaRequestHandler.java    From kop with Apache License 2.0 6 votes vote down vote up
static PartitionMetadata newFailedPartitionMetadata(TopicName topicName) {
    int pulsarPartitionIndex = topicName.getPartitionIndex();
    int kafkaPartitionIndex = pulsarPartitionIndex == -1 ? 0 : pulsarPartitionIndex;

    log.warn("Failed find Broker metadata, create PartitionMetadata with NOT_LEADER_FOR_PARTITION");

    // most of this error happens when topic is in loading/unloading status,
    return new PartitionMetadata(
        Errors.NOT_LEADER_FOR_PARTITION,
        kafkaPartitionIndex,
        Node.noNode(),                      // leader
        Lists.newArrayList(Node.noNode()),  // replicas
        Lists.newArrayList(Node.noNode()),  // isr
        Collections.emptyList()             // offline replicas
    );
}
 
Example #6
Source File: ExecutorAdminUtils.java    From cruise-control with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Check whether there is ongoing intra-broker replica movement.
 * @param brokersToCheck List of broker to check.
 * @param adminClient The adminClient to send describeLogDirs request.
 * @param config The config object that holds all the Cruise Control related configs
 * @return True if there is ongoing intra-broker replica movement.
 */
static boolean hasOngoingIntraBrokerReplicaMovement(Collection<Integer> brokersToCheck, AdminClient adminClient,
                                                    KafkaCruiseControlConfig config)
    throws InterruptedException, ExecutionException, TimeoutException {
  Map<Integer, KafkaFuture<Map<String, LogDirInfo>>> logDirsByBrokerId = adminClient.describeLogDirs(brokersToCheck).values();
  for (Map.Entry<Integer, KafkaFuture<Map<String, LogDirInfo>>> entry : logDirsByBrokerId.entrySet()) {
    Map<String, LogDirInfo> logInfos = entry.getValue().get(config.getLong(LOGDIR_RESPONSE_TIMEOUT_MS_CONFIG), TimeUnit.MILLISECONDS);
    for (LogDirInfo info : logInfos.values()) {
      if (info.error == Errors.NONE) {
        if (info.replicaInfos.values().stream().anyMatch(i -> i.isFuture)) {
          return true;
        }
      }
    }
  }
  return false;
}
 
Example #7
Source File: GroupCoordinator.java    From kop with Apache License 2.0 6 votes vote down vote up
public CompletableFuture<KeyValue<Errors, byte[]>> handleSyncGroup(
    String groupId,
    int generation,
    String memberId,
    Map<String, byte[]> groupAssignment
) {
    CompletableFuture<KeyValue<Errors, byte[]>> resultFuture = new CompletableFuture<>();
    handleSyncGroup(
        groupId,
        generation,
        memberId,
        groupAssignment,
        (assignment, errors) -> resultFuture.complete(
            new KeyValue<>(errors, assignment))
    );

    resultFuture.whenCompleteAsync((kv, throwable) -> {
        if (throwable == null && kv.getKey() == Errors.NONE) {
            offsetAcker.addOffsetsTracker(groupId, kv.getValue());
        }
    });
    return resultFuture;
}
 
Example #8
Source File: TopicPartitionsOffsetInfo.java    From kafka-utilities with Apache License 2.0 6 votes vote down vote up
public Map<TopicPartition, OffsetFetchResponse.PartitionData> getCommitedOffsets(final String groupName, final List<TopicPartition> topicPartitions,
                                                                                 final long responseWaitTime) throws OffsetFetchException {
    if(this.coordinator == null){
        throw new OffsetFetchException("Missing Group Coordinator for group:" + groupName);
    }

    OffsetFetchRequest.Builder offsetRequestBuilder =
            new OffsetFetchRequest.Builder(groupName, topicPartitions);
    this.kafkaApiRequest.sendApiRequest(this.coordinator, offsetRequestBuilder);
    OffsetFetchResponse offsetFetchResponse =(OffsetFetchResponse) this.kafkaApiRequest.getLastApiResponse(responseWaitTime);
    if(offsetFetchResponse.error() == Errors.NONE) {
        return offsetFetchResponse.responseData();
    }else{
        throw new OffsetFetchException(offsetFetchResponse.error().message());
    }
}
 
Example #9
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerationIdIncrementsOnRebalance() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, newProtocols()
    );
    String assignedMemberId = joinGroupResult.getMemberId();
    int initialGenerationId = joinGroupResult.getGenerationId();
    Errors joinGroupError = joinGroupResult.getError();
    assertEquals(1, initialGenerationId);
    assertEquals(Errors.NONE, joinGroupError);

    Map<String, byte[]> assignments = new HashMap<>();
    assignments.put(assignedMemberId, new byte[0]);
    KeyValue<Errors, byte[]> syncGroupResult = groupCoordinator.handleSyncGroup(
        groupId, initialGenerationId, assignedMemberId, assignments).get();
    assertEquals(Errors.NONE, syncGroupResult.getKey());

    JoinGroupResult otherJoinGroupResult = joinGroup(groupId, assignedMemberId, protocolType, newProtocols());

    int nextGenerationId = otherJoinGroupResult.getGenerationId();
    assertEquals(2, nextGenerationId);
    assertEquals(Errors.NONE, otherJoinGroupResult.getError());
}
 
Example #10
Source File: KafkaRequestHandler.java    From kop with Apache License 2.0 6 votes vote down vote up
protected ApiVersionsResponse overloadDefaultApiVersionsResponse() {
    List<ApiVersionsResponse.ApiVersion> versionList = new ArrayList<>();
    for (ApiKeys apiKey : ApiKeys.values()) {
        if (apiKey.minRequiredInterBrokerMagic <= RecordBatch.CURRENT_MAGIC_VALUE) {
            switch (apiKey) {
                case FETCH:
                    // V4 added MessageSets responses. We need to make sure RecordBatch format is not used
                    versionList.add(new ApiVersionsResponse.ApiVersion((short) 1, (short) 4,
                            apiKey.latestVersion()));
                    break;
                case LIST_OFFSETS:
                    // V0 is needed for librdkafka
                    versionList.add(new ApiVersionsResponse.ApiVersion((short) 2, (short) 0,
                            apiKey.latestVersion()));
                    break;
                default:
                    versionList.add(new ApiVersionsResponse.ApiVersion(apiKey));
            }
        }
    }
    return new ApiVersionsResponse(0, Errors.NONE, versionList);
}
 
Example #11
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 6 votes vote down vote up
@Test
public void testCommitOffsetInCompletingRebalance() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    TopicPartition tp = new TopicPartition("topic", 0);
    OffsetAndMetadata offset = OffsetAndMetadata.apply(0);

    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, protocols
    );
    String assignedMemberId = joinGroupResult.getMemberId();
    int generationId = joinGroupResult.getGenerationId();
    Errors joinGroupError = joinGroupResult.getError();
    assertEquals(Errors.NONE, joinGroupError);

    Map<TopicPartition, Errors> commitOffsetResult = groupCoordinator.handleCommitOffsets(
        groupId, assignedMemberId, generationId,
        ImmutableMap.<TopicPartition, OffsetAndMetadata>builder()
            .put(tp, offset)
            .build()
    ).get();
    assertEquals(Errors.REBALANCE_IN_PROGRESS, commitOffsetResult.get(tp));
}
 
Example #12
Source File: GroupCoordinator.java    From kop with Apache License 2.0 6 votes vote down vote up
public KeyValue<Errors, Map<TopicPartition, PartitionData>> handleFetchOffsets(
    String groupId,
    Optional<List<TopicPartition>> partitions
) {
    return validateGroupStatus(groupId, ApiKeys.OFFSET_FETCH).map(errors ->
        new KeyValue<Errors, Map<TopicPartition, PartitionData>>(
            errors,
            new HashMap<>()
        )
    ).orElseGet(() ->
        new KeyValue<>(
            Errors.NONE,
            groupManager.getOffsets(groupId, partitions)
        )
    );
}
 
Example #13
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 6 votes vote down vote up
@Test
public void testHeartbeatUnknowConsumerExistingGroup() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    String otherMemberId = "memberId";

    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, protocols
    );
    String assignedMemberId = joinGroupResult.getMemberId();
    Errors joinGroupErrors = joinGroupResult.getError();
    assertEquals(Errors.NONE, joinGroupErrors);

    KeyValue<Errors, byte[]> syncGroupResult = groupCoordinator.handleSyncGroup(
        groupId, joinGroupResult.getGenerationId(), assignedMemberId,
        ImmutableMap.<String, byte[]>builder()
            .put(assignedMemberId, new byte[0])
            .build()
    ).get();
    assertEquals(Errors.NONE, syncGroupResult.getKey());

    Errors heartbeatResult = groupCoordinator.handleHeartbeat(
        groupId, otherMemberId, 1
    ).get();
    assertEquals(Errors.UNKNOWN_MEMBER_ID, heartbeatResult);
}
 
Example #14
Source File: GroupCoordinator.java    From DataLink with Apache License 2.0 6 votes vote down vote up
public void handleSyncGroup(String groupId,
                            Integer generation,
                            String memberId,
                            Map<String, byte[]> groupAssignment,
                            Callbacks.SyncCallback responseCallback) {
    if (!isActive.get()) {
        responseCallback.response(new byte[0], Errors.GROUP_COORDINATOR_NOT_AVAILABLE.code());
    } else if (!isCoordinatorForGroup(groupId)) {
        responseCallback.response(new byte[0], Errors.NOT_COORDINATOR_FOR_GROUP.code());
    } else {
        GroupMetadata currentGroup = groupManager.getGroup(groupId);
        if (currentGroup == null) {
            responseCallback.response(new byte[0], Errors.UNKNOWN_MEMBER_ID.code());
        } else {
            doSyncGroup(currentGroup, generation, memberId, groupAssignment, responseCallback);
        }
    }
}
 
Example #15
Source File: KarelDbCoordinatorTest.java    From kareldb with Apache License 2.0 6 votes vote down vote up
private JoinGroupResponse joinGroupLeaderResponse(
    int generationId,
    String memberId,
    Map<String, KarelDbIdentity> memberMasterEligibility,
    Errors error
) {
    List<JoinGroupResponseData.JoinGroupResponseMember> metadata = new ArrayList<>();
    for (Map.Entry<String, KarelDbIdentity> configStateEntry : memberMasterEligibility.entrySet()) {
        KarelDbIdentity memberIdentity = configStateEntry.getValue();
        ByteBuffer buf = KarelDbProtocol.serializeMetadata(memberIdentity);
        metadata.add(new JoinGroupResponseData.JoinGroupResponseMember()
            .setMemberId(configStateEntry.getKey())
            .setMetadata(buf.array()));
    }
    return new JoinGroupResponse(new JoinGroupResponseData()
        .setErrorCode(error.code())
        .setGenerationId(generationId)
        .setProtocolName(KarelDbCoordinator.KDB_SUBPROTOCOL_V0)
        .setMemberId(memberId)
        .setLeader(memberId)
        .setMembers(metadata));
}
 
Example #16
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 6 votes vote down vote up
@Test
public void testHeartbeatIllegalGeneration() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, protocols
    );
    String assignedMemberId = joinGroupResult.getMemberId();
    Errors joinGroupError = joinGroupResult.getError();
    assertEquals(Errors.NONE, joinGroupError);

    KeyValue<Errors, byte[]> syncGroupResult = groupCoordinator.handleSyncGroup(
        groupId, joinGroupResult.getGenerationId(), assignedMemberId,
        ImmutableMap.<String, byte[]>builder()
            .put(assignedMemberId, new byte[0])
            .build()
    ).get();
    assertEquals(Errors.NONE, syncGroupResult.getKey());

    Errors heartbeatResult = groupCoordinator.handleHeartbeat(
        groupId, assignedMemberId, 2
    ).get();
    assertEquals(Errors.ILLEGAL_GENERATION, heartbeatResult);
}
 
Example #17
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidHeartbeat() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, protocols
    );
    String assignedConsumerId = joinGroupResult.getMemberId();
    int generationId = joinGroupResult.getGenerationId();
    Errors joinGroupError = joinGroupResult.getError();
    assertEquals(Errors.NONE, joinGroupError);

    KeyValue<Errors, byte[]> syncGroupResult = groupCoordinator.handleSyncGroup(
        groupId, generationId, assignedConsumerId,
        ImmutableMap.<String, byte[]>builder()
            .put(assignedConsumerId, new byte[0])
            .build()
    ).get();
    assertEquals(Errors.NONE, syncGroupResult.getKey());

    Errors heartbeatResult = groupCoordinator.handleHeartbeat(
        groupId, assignedConsumerId, 1
    ).get();
    assertEquals(Errors.NONE, heartbeatResult);
}
 
Example #18
Source File: TopicPartitionsOffsetInfo.java    From kafka-utilities with Apache License 2.0 6 votes vote down vote up
private Map<TopicPartition, Long> processListOffsetResponse(final ListOffsetResponse listOffsetResponse, final Map<TopicPartition, Long>requiredTimestamp) {

        Map<TopicPartition, Long>processTopicPartitionOffsets = new HashMap<>();
        processTopicPartitionOffsets.putAll(requiredTimestamp);
        for (Map.Entry<TopicPartition, Long> entry : requiredTimestamp.entrySet()) {
            TopicPartition topicPartition = entry.getKey();
            ListOffsetResponse.PartitionData partitionData = listOffsetResponse.responseData().get(topicPartition);
            Errors error = partitionData.error;
            if (error == Errors.NONE) {
                //supporting kafka version greater than 10 only
                if (partitionData.offset != ListOffsetResponse.UNKNOWN_OFFSET) {
                    processTopicPartitionOffsets.put(topicPartition, partitionData.offset);
                }
            }
        }
        return processTopicPartitionOffsets;
    }
 
Example #19
Source File: KafkaPartitionLevelConsumerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Override
public FetchResponse fetch(FetchRequest request) {
  scala.collection.Traversable<Tuple2<TopicAndPartition, PartitionFetchInfo>> requestInfo = request.requestInfo();
  java.util.Map<TopicAndPartition, Short> errorMap = new HashMap<>();

  while (requestInfo.headOption().isDefined()) {
    // jfim: IntelliJ erroneously thinks the following line is an incompatible type error, but it's only because
    // it doesn't understand scala covariance when called from Java (ie. it thinks head() is of type A even though
    // it's really of type Tuple2[TopicAndPartition, PartitionFetchInfo])
    Tuple2<TopicAndPartition, PartitionFetchInfo> t2 = requestInfo.head();
    TopicAndPartition topicAndPartition = t2._1();
    PartitionFetchInfo partitionFetchInfo = t2._2();

    if (!topicAndPartition.topic().equals(topicName)) {
      errorMap.put(topicAndPartition, Errors.UNKNOWN_TOPIC_OR_PARTITION.code());
    } else if (partitionLeaderIndices.length < topicAndPartition.partition()) {
      errorMap.put(topicAndPartition, Errors.UNKNOWN_TOPIC_OR_PARTITION.code());
    } else if (partitionLeaderIndices[topicAndPartition.partition()] != index) {
      errorMap.put(topicAndPartition, Errors.NOT_LEADER_FOR_PARTITION.code());
    } else {
      // Do nothing, we'll generate a fake message
    }

    requestInfo = requestInfo.tail();
  }

  return new MockFetchResponse(errorMap);
}
 
Example #20
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testJoinGroupIncosistentProtocolType() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    String otherMemberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, protocols
    );
    assertEquals(Errors.NONE, joinGroupResult.getError());

    JoinGroupResult otherJoinGroupResult = joinGroup(
        groupId, otherMemberId, "connect", protocols
    );
    assertEquals(Errors.INCONSISTENT_GROUP_PROTOCOL, otherJoinGroupResult.getError());
}
 
Example #21
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testJoinGroupWithEmptyProtocolType() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, "", protocols
    );
    assertEquals(Errors.INCONSISTENT_GROUP_PROTOCOL, joinGroupResult.getError());
}
 
Example #22
Source File: GroupCoordinator.java    From DataLink with Apache License 2.0 5 votes vote down vote up
public void handleLeaveGroup(
        String groupId,
        String memberId,
        Callbacks.LeaveGroupCallback responseCallback
) {
    if (!isActive.get()) {
        responseCallback.response(Errors.GROUP_COORDINATOR_NOT_AVAILABLE.code());
    } else if (!isCoordinatorForGroup(groupId)) {
        responseCallback.response(Errors.NOT_COORDINATOR_FOR_GROUP.code());
    } else if (isCoordinatorLoadingInProgress(groupId)) {
        // the group is still loading, so respond just blindly
        responseCallback.response(Errors.GROUP_LOAD_IN_PROGRESS.code());
    } else {
        GroupMetadata group = groupManager.getGroup(groupId);
        if (group == null) {
            // if the group is marked as dead, it means some other thread has just removed the group
            // parseFrom the coordinator metadata; this is likely that the group has migrated to some other
            // coordinator OR the group is in a transient unstable phase. Let the consumer to retry
            // joining without specified consumer id,
            responseCallback.response(Errors.UNKNOWN_MEMBER_ID.code());
        } else {
            synchronized (group) {
                if (group.is(GroupState.Dead) || !group.has(memberId)) {
                    responseCallback.response(Errors.UNKNOWN_MEMBER_ID.code());
                } else {
                    MemberMetadata member = group.get(memberId);
                    removeHeartbeatForLeavingMember(group, member);
                    onMemberFailure(group, member);
                    responseCallback.response(Errors.NONE.code());
                }
            }
        }
    }
}
 
Example #23
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteGroupWithInvalidGroupId() throws Exception {
    String invalidGroupId = null;
    Map<String, Errors> deleteResult = groupCoordinator.handleDeleteGroups(
        Sets.newHashSet(invalidGroupId)
    );
    assertEquals(1, deleteResult.size());
    assertTrue(deleteResult.containsKey(invalidGroupId));
    assertEquals(Errors.INVALID_GROUP_ID, deleteResult.get(invalidGroupId));
}
 
Example #24
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testLeaveGroupUnknownGroup() throws Exception {
    Errors leaveGroupResult = groupCoordinator.handleLeaveGroup(
        groupId, memberId
    ).get();
    assertEquals(Errors.UNKNOWN_MEMBER_ID, leaveGroupResult);
}
 
Example #25
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidGroupId() throws Exception {
    String groupId = "";
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, protocols
    );
    assertEquals(Errors.INVALID_GROUP_ID, joinGroupResult.getError());
}
 
Example #26
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testJoinGroupSessionTimeoutTooSmall() throws Exception {
    String memberId = JoinGroupRequest.UNKNOWN_MEMBER_ID;
    JoinGroupResult joinGroupResult = joinGroup(
        groupId, memberId, protocolType, protocols,
        ConsumerMinSessionTimeout - 1
    );
    assertEquals(Errors.INVALID_SESSION_TIMEOUT, joinGroupResult.getError());
}
 
Example #27
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testFetchOffsetForUnknownPartition() {
    TopicPartition tp = new TopicPartition("topic", 0);
    KeyValue<Errors, Map<TopicPartition, PartitionData>> fetchOffsetsResult =
        groupCoordinator.handleFetchOffsets(
            groupId, Optional.of(Lists.newArrayList(tp)));
    assertEquals(Errors.NONE, fetchOffsetsResult.getKey());
    assertEquals(OffsetFetchResponse.INVALID_OFFSET, fetchOffsetsResult.getValue().get(tp).offset);
}
 
Example #28
Source File: GroupCoordinator.java    From kop with Apache License 2.0 5 votes vote down vote up
public KeyValue<Errors, GroupSummary> handleDescribeGroup(String groupId) {
    return validateGroupStatus(groupId, ApiKeys.DESCRIBE_GROUPS).map(error ->
        new KeyValue<>(error, GroupCoordinator.EmptyGroup)
    ).orElseGet(() ->
        groupManager.getGroup(groupId)
            .map(group ->
                group.inLock(() -> new KeyValue<>(Errors.NONE, group.summary())
                ))
            .orElseGet(() -> new KeyValue<>(Errors.NONE, GroupCoordinator.DeadGroup))
    );
}
 
Example #29
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncGroupOtherGroupId() throws Exception {
    int generation = 1;
    KeyValue<Errors, byte[]> syncGroupResult = groupCoordinator.handleSyncGroup(
        otherGroupId, generation, memberId,
        ImmutableMap.<String, byte[]>builder()
            .build()
    ).get();
    assertEquals(Errors.NOT_COORDINATOR, syncGroupResult.getKey());
}
 
Example #30
Source File: GroupCoordinatorTest.java    From kop with Apache License 2.0 5 votes vote down vote up
@Test
public void testCommitAndFetchOffsetsWithEmptyGroup() throws Exception {
    // For backwards compatibility, the coordinator supports committing/fetching offsets with an empty groupId.
    // To allow inspection and removal of the empty group, we must also support DescribeGroups and DeleteGroups

    TopicPartition tp = new TopicPartition("topic", 0);
    OffsetAndMetadata offset = OffsetAndMetadata.apply(0);
    String groupId = "";

    Map<TopicPartition, Errors> commitOffsetResult = groupCoordinator.handleCommitOffsets(
        groupId, OffsetCommitRequest.DEFAULT_MEMBER_ID, OffsetCommitRequest.DEFAULT_GENERATION_ID,
        ImmutableMap.<TopicPartition, OffsetAndMetadata>builder()
            .put(tp, offset)
            .build()
    ).get();
    assertEquals(Errors.NONE, commitOffsetResult.get(tp));

    KeyValue<Errors, Map<TopicPartition, PartitionData>> fetchOffsetsResult =
        groupCoordinator.handleFetchOffsets(groupId, Optional.of(Lists.newArrayList(tp)));
    assertEquals(Errors.NONE, fetchOffsetsResult.getKey());
    assertEquals(0, fetchOffsetsResult.getValue().get(tp).offset);

    KeyValue<Errors, GroupSummary> describeGroupResult = groupCoordinator.handleDescribeGroup(groupId);
    assertEquals(Errors.NONE, describeGroupResult.getKey());
    assertEquals(GroupState.Empty.toString(), describeGroupResult.getValue().state());

    TopicPartition groupTopicPartition = new TopicPartition(
        Topic.GROUP_METADATA_TOPIC_NAME, groupPartitionId
    );

    Map<String, Errors> deleteErrors = groupCoordinator.handleDeleteGroups(Sets.newHashSet(groupId));
    assertEquals(Errors.NONE, deleteErrors.get(groupId));

    KeyValue<Errors, Map<TopicPartition, PartitionData>> fetchOffsetsResult2 =
        groupCoordinator.handleFetchOffsets(groupId, Optional.of(Lists.newArrayList(tp)));
    assertEquals(Errors.NONE, fetchOffsetsResult2.getKey());
    assertEquals(OffsetFetchResponse.INVALID_OFFSET, fetchOffsetsResult2.getValue().get(tp).offset);
}