Search in sources :

Example 51 with Arrays.asList

use of java.util.Arrays.asList in project jnosql-diana-driver by eclipse.

the class ElasticsearchDocumentCollectionManagerTest method shouldSaveSubDocument2.

@Test
public void shouldSaveSubDocument2() {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
    DocumentEntity entitySaved = entityManager.insert(entity);
    Document id = entitySaved.find("_id").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentEntity entityFound = entityManager.select(query).get(0);
    Document subDocument = entityFound.find("phones").get();
    List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 52 with Arrays.asList

use of java.util.Arrays.asList in project jnosql-artemis by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertEntityFromDocumentEntity2.

@Test
public void shouldConvertEntityFromDocumentEntity2() {
    Movie movie = new Movie("Matriz", 2012, singleton("Actor"));
    Director director = Director.builderDiretor().withAge(12).withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).withMovie(movie).build();
    DocumentEntity entity = converter.toDocument(director);
    assertEquals(5, entity.size());
    assertEquals(getValue(entity.find("name")), director.getName());
    assertEquals(getValue(entity.find("age")), director.getAge());
    assertEquals(getValue(entity.find("_id")), director.getId());
    assertEquals(getValue(entity.find("phones")), director.getPhones());
    Document subdocument = entity.find("movie").get();
    List<Document> documents = subdocument.get(new TypeReference<List<Document>>() {
    });
    assertEquals(3, documents.size());
    assertEquals("movie", subdocument.getName());
    assertEquals(movie.getTitle(), getValue(documents.stream().filter(d -> "title".equals(d.getName())).findFirst()));
    assertEquals(movie.getYear(), getValue(documents.stream().filter(d -> "year".equals(d.getName())).findFirst()));
    assertEquals(movie.getActors(), getValue(documents.stream().filter(d -> "actors".equals(d.getName())).findFirst()));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) Money(org.jnosql.artemis.model.Money) TypeReference(org.jnosql.diana.api.TypeReference) Address(org.jnosql.artemis.model.Address) HashMap(java.util.HashMap) Job(org.jnosql.artemis.model.Job) ArrayList(java.util.ArrayList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) BigDecimal(java.math.BigDecimal) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Actor(org.jnosql.artemis.model.Actor) Collection(java.util.Collection) ContactType(org.jnosql.artemis.model.ContactType) Matchers(org.hamcrest.Matchers) Zipcode(org.jnosql.artemis.model.Zipcode) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test) AppointmentBook(org.jnosql.artemis.model.AppointmentBook) List(java.util.List) Stream(java.util.stream.Stream) Movie(org.jnosql.artemis.model.Movie) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Value(org.jnosql.diana.api.Value) Optional(java.util.Optional) Contact(org.jnosql.artemis.model.Contact) Collections(java.util.Collections) Worker(org.jnosql.artemis.model.Worker) Movie(org.jnosql.artemis.model.Movie) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Director(org.jnosql.artemis.model.Director) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 53 with Arrays.asList

use of java.util.Arrays.asList in project kafka by apache.

the class KafkaAdminClientTest method testRemoveMembersFromGroup.

@Test
public void testRemoveMembersFromGroup() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        final String instanceOne = "instance-1";
        final String instanceTwo = "instance-2";
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        // Retriable FindCoordinatorResponse errors should be retried
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.COORDINATOR_LOAD_IN_PROGRESS, Node.noNode()));
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        // Retriable errors should be retried
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.COORDINATOR_LOAD_IN_PROGRESS.code())));
        // Inject a top-level non-retriable error
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.UNKNOWN_SERVER_ERROR.code())));
        Collection<MemberToRemove> membersToRemove = Arrays.asList(new MemberToRemove(instanceOne), new MemberToRemove(instanceTwo));
        final RemoveMembersFromConsumerGroupResult unknownErrorResult = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, new RemoveMembersFromConsumerGroupOptions(membersToRemove));
        MemberToRemove memberOne = new MemberToRemove(instanceOne);
        MemberToRemove memberTwo = new MemberToRemove(instanceTwo);
        TestUtils.assertFutureError(unknownErrorResult.memberResult(memberOne), UnknownServerException.class);
        TestUtils.assertFutureError(unknownErrorResult.memberResult(memberTwo), UnknownServerException.class);
        MemberResponse responseOne = new MemberResponse().setGroupInstanceId(instanceOne).setErrorCode(Errors.UNKNOWN_MEMBER_ID.code());
        MemberResponse responseTwo = new MemberResponse().setGroupInstanceId(instanceTwo).setErrorCode(Errors.NONE.code());
        // Inject one member level error.
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(Arrays.asList(responseOne, responseTwo))));
        final RemoveMembersFromConsumerGroupResult memberLevelErrorResult = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, new RemoveMembersFromConsumerGroupOptions(membersToRemove));
        TestUtils.assertFutureError(memberLevelErrorResult.all(), UnknownMemberIdException.class);
        TestUtils.assertFutureError(memberLevelErrorResult.memberResult(memberOne), UnknownMemberIdException.class);
        assertNull(memberLevelErrorResult.memberResult(memberTwo).get());
        // Return with missing member.
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(Collections.singletonList(responseTwo))));
        final RemoveMembersFromConsumerGroupResult missingMemberResult = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, new RemoveMembersFromConsumerGroupOptions(membersToRemove));
        TestUtils.assertFutureError(missingMemberResult.all(), IllegalArgumentException.class);
        // The memberOne was not included in the response.
        TestUtils.assertFutureError(missingMemberResult.memberResult(memberOne), IllegalArgumentException.class);
        assertNull(missingMemberResult.memberResult(memberTwo).get());
        // Return with success.
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(Arrays.asList(responseTwo, new MemberResponse().setGroupInstanceId(instanceOne).setErrorCode(Errors.NONE.code())))));
        final RemoveMembersFromConsumerGroupResult noErrorResult = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, new RemoveMembersFromConsumerGroupOptions(membersToRemove));
        assertNull(noErrorResult.all().get());
        assertNull(noErrorResult.memberResult(memberOne).get());
        assertNull(noErrorResult.memberResult(memberTwo).get());
        // Test the "removeAll" scenario
        final List<TopicPartition> topicPartitions = Arrays.asList(1, 2, 3).stream().map(partition -> new TopicPartition("my_topic", partition)).collect(Collectors.toList());
        // construct the DescribeGroupsResponse
        DescribeGroupsResponseData data = prepareDescribeGroupsResponseData(GROUP_ID, Arrays.asList(instanceOne, instanceTwo), topicPartitions);
        // Return with partial failure for "removeAll" scenario
        // 1 prepare response for AdminClient.describeConsumerGroups
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new DescribeGroupsResponse(data));
        // 2 KafkaAdminClient encounter partial failure when trying to delete all members
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(Arrays.asList(responseOne, responseTwo))));
        final RemoveMembersFromConsumerGroupResult partialFailureResults = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, new RemoveMembersFromConsumerGroupOptions());
        ExecutionException exception = assertThrows(ExecutionException.class, () -> partialFailureResults.all().get());
        assertTrue(exception.getCause() instanceof KafkaException);
        assertTrue(exception.getCause().getCause() instanceof UnknownMemberIdException);
        // Return with success for "removeAll" scenario
        // 1 prepare response for AdminClient.describeConsumerGroups
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new DescribeGroupsResponse(data));
        // 2. KafkaAdminClient should delete all members correctly
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(Arrays.asList(responseTwo, new MemberResponse().setGroupInstanceId(instanceOne).setErrorCode(Errors.NONE.code())))));
        final RemoveMembersFromConsumerGroupResult successResult = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, new RemoveMembersFromConsumerGroupOptions());
        assertNull(successResult.all().get());
    }
}
Also used : MemberResponse(org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse) ListGroupsResponse(org.apache.kafka.common.requests.ListGroupsResponse) ThrottlingQuotaExceededException(org.apache.kafka.common.errors.ThrottlingQuotaExceededException) ListOffsetsRequest(org.apache.kafka.common.requests.ListOffsetsRequest) ClientQuotaFilter(org.apache.kafka.common.quota.ClientQuotaFilter) AclPermissionType(org.apache.kafka.common.acl.AclPermissionType) LeaveGroupRequest(org.apache.kafka.common.requests.LeaveGroupRequest) KafkaException(org.apache.kafka.common.KafkaException) ListTransactionsRequest(org.apache.kafka.common.requests.ListTransactionsRequest) Collections.singletonList(java.util.Collections.singletonList) ClientUtils(org.apache.kafka.clients.ClientUtils) Future(java.util.concurrent.Future) DescribeTransactionsRequest(org.apache.kafka.common.requests.DescribeTransactionsRequest) PartitionResult(org.apache.kafka.common.message.ElectLeadersResponseData.PartitionResult) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DeletableTopicResultCollection(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResultCollection) DescribeLogDirsResponseData(org.apache.kafka.common.message.DescribeLogDirsResponseData) ClientQuotaAlteration(org.apache.kafka.common.quota.ClientQuotaAlteration) AlterReplicaLogDirTopicResult(org.apache.kafka.common.message.AlterReplicaLogDirsResponseData.AlterReplicaLogDirTopicResult) AlterReplicaLogDirsResponseData(org.apache.kafka.common.message.AlterReplicaLogDirsResponseData) ListGroupsRequest(org.apache.kafka.common.requests.ListGroupsRequest) CountDownLatch(java.util.concurrent.CountDownLatch) DeleteTopicsResponseData(org.apache.kafka.common.message.DeleteTopicsResponseData) Stream(java.util.stream.Stream) ApiMessageType(org.apache.kafka.common.message.ApiMessageType) MetadataResponsePartition(org.apache.kafka.common.message.MetadataResponseData.MetadataResponsePartition) DescribeGroupsResponse(org.apache.kafka.common.requests.DescribeGroupsResponse) ListOffsetsTopicResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsTopicResponse) Errors(org.apache.kafka.common.protocol.Errors) Node(org.apache.kafka.common.Node) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) DescribedGroupMember(org.apache.kafka.common.message.DescribeGroupsResponseData.DescribedGroupMember) NodeApiVersions(org.apache.kafka.clients.NodeApiVersions) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException) Assertions.fail(org.junit.jupiter.api.Assertions.fail) AlterUserScramCredentialsResponseData(org.apache.kafka.common.message.AlterUserScramCredentialsResponseData) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CreatableTopicResultCollection(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResultCollection) AlterUserScramCredentialsResponse(org.apache.kafka.common.requests.AlterUserScramCredentialsResponse) ClientDnsLookup(org.apache.kafka.clients.ClientDnsLookup) DescribeClusterResponse(org.apache.kafka.common.requests.DescribeClusterResponse) WriteTxnMarkersRequest(org.apache.kafka.common.requests.WriteTxnMarkersRequest) DescribeClusterBroker(org.apache.kafka.common.message.DescribeClusterResponseData.DescribeClusterBroker) DescribeAclsResponse(org.apache.kafka.common.requests.DescribeAclsResponse) WriteTxnMarkersResponseData(org.apache.kafka.common.message.WriteTxnMarkersResponseData) SecurityDisabledException(org.apache.kafka.common.errors.SecurityDisabledException) AlterReplicaLogDirsResponse(org.apache.kafka.common.requests.AlterReplicaLogDirsResponse) OptionalLong(java.util.OptionalLong) UnregisterBrokerResponseData(org.apache.kafka.common.message.UnregisterBrokerResponseData) UpdateFeaturesRequest(org.apache.kafka.common.requests.UpdateFeaturesRequest) OffsetCommitResponse(org.apache.kafka.common.requests.OffsetCommitResponse) DescribeTransactionsResponseData(org.apache.kafka.common.message.DescribeTransactionsResponseData) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) OffsetDeleteResponsePartitionCollection(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartitionCollection) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IncrementalAlterConfigsResponse(org.apache.kafka.common.requests.IncrementalAlterConfigsResponse) MemberResponse(org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse) FilterResults(org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults) JoinGroupRequest(org.apache.kafka.common.requests.JoinGroupRequest) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) DescribeUserScramCredentialsResponse(org.apache.kafka.common.requests.DescribeUserScramCredentialsResponse) CredentialInfo(org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData.CredentialInfo) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) MemberIdentity(org.apache.kafka.common.message.LeaveGroupRequestData.MemberIdentity) DeletableGroupResult(org.apache.kafka.common.message.DeleteGroupsResponseData.DeletableGroupResult) LeaveGroupRequestData(org.apache.kafka.common.message.LeaveGroupRequestData) ReplicaElectionResult(org.apache.kafka.common.message.ElectLeadersResponseData.ReplicaElectionResult) DescribeConfigsResponseData(org.apache.kafka.common.message.DescribeConfigsResponseData) ApiVersionsResponseData(org.apache.kafka.common.message.ApiVersionsResponseData) TopicPartition(org.apache.kafka.common.TopicPartition) Time(org.apache.kafka.common.utils.Time) Collection(java.util.Collection) CreateAclsResponse(org.apache.kafka.common.requests.CreateAclsResponse) DescribeClusterRequest(org.apache.kafka.common.requests.DescribeClusterRequest) DescribeUserScramCredentialsResponseData(org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData) DescribeTransactionsResponse(org.apache.kafka.common.requests.DescribeTransactionsResponse) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ResourceType(org.apache.kafka.common.resource.ResourceType) CreatePartitionsResponse(org.apache.kafka.common.requests.CreatePartitionsResponse) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Uuid(org.apache.kafka.common.Uuid) DeleteTopicsRequest(org.apache.kafka.common.requests.DeleteTopicsRequest) ReassignablePartitionResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignablePartitionResponse) OffsetDeleteResponseTopicCollection(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopicCollection) DeleteAclsResponse(org.apache.kafka.common.requests.DeleteAclsResponse) ListPartitionReassignmentsResponseData(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData) AlterPartitionReassignmentsResponse(org.apache.kafka.common.requests.AlterPartitionReassignmentsResponse) CompletableFuture(java.util.concurrent.CompletableFuture) DescribeConfigsResponse(org.apache.kafka.common.requests.DescribeConfigsResponse) PatternType(org.apache.kafka.common.resource.PatternType) OptionalInt(java.util.OptionalInt) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) DeleteRecordsResponseData(org.apache.kafka.common.message.DeleteRecordsResponseData) HashSet(java.util.HashSet) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) AlterConfigsResourceResponse(org.apache.kafka.common.message.IncrementalAlterConfigsResponseData.AlterConfigsResourceResponse) TopicCollection(org.apache.kafka.common.TopicCollection) OngoingPartitionReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingPartitionReassignment) UnknownMemberIdException(org.apache.kafka.common.errors.UnknownMemberIdException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) DeletableGroupResultCollection(org.apache.kafka.common.message.DeleteGroupsResponseData.DeletableGroupResultCollection) MockClient(org.apache.kafka.clients.MockClient) Logger(org.slf4j.Logger) GroupSubscribedToTopicException(org.apache.kafka.common.errors.GroupSubscribedToTopicException) CreateTopicsResponse(org.apache.kafka.common.requests.CreateTopicsResponse) Semaphore(java.util.concurrent.Semaphore) LeaveGroupResponseData(org.apache.kafka.common.message.LeaveGroupResponseData) ConfigException(org.apache.kafka.common.config.ConfigException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) InvalidRequestException(org.apache.kafka.common.errors.InvalidRequestException) MockTime(org.apache.kafka.common.utils.MockTime) Arrays(java.util.Arrays) ApiVersionsRequest(org.apache.kafka.common.requests.ApiVersionsRequest) NotLeaderOrFollowerException(org.apache.kafka.common.errors.NotLeaderOrFollowerException) Cluster(org.apache.kafka.common.Cluster) ApiVersionsResponse(org.apache.kafka.common.requests.ApiVersionsResponse) ListOffsetsResponse(org.apache.kafka.common.requests.ListOffsetsResponse) DescribeAclsResponseData(org.apache.kafka.common.message.DescribeAclsResponseData) TestUtils(org.apache.kafka.test.TestUtils) InvalidTopicException(org.apache.kafka.common.errors.InvalidTopicException) Set(java.util.Set) PartitionInfo(org.apache.kafka.common.PartitionInfo) DeleteGroupsResponse(org.apache.kafka.common.requests.DeleteGroupsResponse) ListTransactionsResponse(org.apache.kafka.common.requests.ListTransactionsResponse) TopicDeletionDisabledException(org.apache.kafka.common.errors.TopicDeletionDisabledException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ConsumerGroupState(org.apache.kafka.common.ConsumerGroupState) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DescribeGroupsResponseData(org.apache.kafka.common.message.DescribeGroupsResponseData) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestTestUtils(org.apache.kafka.common.requests.RequestTestUtils) ArrayList(java.util.ArrayList) Features(org.apache.kafka.common.feature.Features) OffsetDeleteResponsePartition(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartition) CreateAclsResponseData(org.apache.kafka.common.message.CreateAclsResponseData) ElectionType(org.apache.kafka.common.ElectionType) FindCoordinatorResponseData(org.apache.kafka.common.message.FindCoordinatorResponseData) MetadataResponseTopic(org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopic) ListTransactionsResponseData(org.apache.kafka.common.message.ListTransactionsResponseData) FindCoordinatorRequest(org.apache.kafka.common.requests.FindCoordinatorRequest) OffsetFetchResponse(org.apache.kafka.common.requests.OffsetFetchResponse) UnknownTopicIdException(org.apache.kafka.common.errors.UnknownTopicIdException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ListGroupsResponseData(org.apache.kafka.common.message.ListGroupsResponseData) SaslAuthenticationException(org.apache.kafka.common.errors.SaslAuthenticationException) ValueSource(org.junit.jupiter.params.provider.ValueSource) AlterClientQuotasResponse(org.apache.kafka.common.requests.AlterClientQuotasResponse) TopicPartitionReplica(org.apache.kafka.common.TopicPartitionReplica) FencedInstanceIdException(org.apache.kafka.common.errors.FencedInstanceIdException) DeleteRecordsResponse(org.apache.kafka.common.requests.DeleteRecordsResponse) LEAVE_GROUP_REASON(org.apache.kafka.clients.admin.KafkaAdminClient.LEAVE_GROUP_REASON) AclOperation(org.apache.kafka.common.acl.AclOperation) DescribeClusterResponseData(org.apache.kafka.common.message.DescribeClusterResponseData) DeleteGroupsResponseData(org.apache.kafka.common.message.DeleteGroupsResponseData) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) WriteTxnMarkersResponse(org.apache.kafka.common.requests.WriteTxnMarkersResponse) ResourcePatternFilter(org.apache.kafka.common.resource.ResourcePatternFilter) CreatePartitionsResponseData(org.apache.kafka.common.message.CreatePartitionsResponseData) FindCoordinatorResponse(org.apache.kafka.common.requests.FindCoordinatorResponse) LoggerFactory(org.slf4j.LoggerFactory) CreatePartitionsTopicResult(org.apache.kafka.common.message.CreatePartitionsResponseData.CreatePartitionsTopicResult) AlterReplicaLogDirPartitionResult(org.apache.kafka.common.message.AlterReplicaLogDirsResponseData.AlterReplicaLogDirPartitionResult) ListPartitionReassignmentsResponse(org.apache.kafka.common.requests.ListPartitionReassignmentsResponse) ByteBuffer(java.nio.ByteBuffer) DescribeClientQuotasResponse(org.apache.kafka.common.requests.DescribeClientQuotasResponse) UpdateFeaturesResponse(org.apache.kafka.common.requests.UpdateFeaturesResponse) ReassignableTopicResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignableTopicResponse) DescribeProducersResponse(org.apache.kafka.common.requests.DescribeProducersResponse) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UnregisterBrokerResponse(org.apache.kafka.common.requests.UnregisterBrokerResponse) CreatePartitionsRequest(org.apache.kafka.common.requests.CreatePartitionsRequest) RecordVersion(org.apache.kafka.common.record.RecordVersion) Collections.emptyList(java.util.Collections.emptyList) KafkaFuture(org.apache.kafka.common.KafkaFuture) LogDirNotFoundException(org.apache.kafka.common.errors.LogDirNotFoundException) InetSocketAddress(java.net.InetSocketAddress) ListOffsetsResponseData(org.apache.kafka.common.message.ListOffsetsResponseData) ListOffsetsResultInfo(org.apache.kafka.clients.admin.ListOffsetsResult.ListOffsetsResultInfo) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) List(java.util.List) DescribeProducersResponseData(org.apache.kafka.common.message.DescribeProducersResponseData) DeletableTopicResult(org.apache.kafka.common.message.DeleteTopicsResponseData.DeletableTopicResult) OffsetDeleteResponseData(org.apache.kafka.common.message.OffsetDeleteResponseData) Optional(java.util.Optional) CreateTopicsResponseData(org.apache.kafka.common.message.CreateTopicsResponseData) ConsumerProtocol(org.apache.kafka.clients.consumer.internals.ConsumerProtocol) ClientQuotaFilterComponent(org.apache.kafka.common.quota.ClientQuotaFilterComponent) CreateTopicsRequest(org.apache.kafka.common.requests.CreateTopicsRequest) ElectLeadersResponse(org.apache.kafka.common.requests.ElectLeadersResponse) AclBindingFilter(org.apache.kafka.common.acl.AclBindingFilter) DescribeLogDirsTopic(org.apache.kafka.common.message.DescribeLogDirsResponseData.DescribeLogDirsTopic) IncrementalAlterConfigsResponseData(org.apache.kafka.common.message.IncrementalAlterConfigsResponseData) AccessControlEntryFilter(org.apache.kafka.common.acl.AccessControlEntryFilter) HashMap(java.util.HashMap) DescribeProducersRequest(org.apache.kafka.common.requests.DescribeProducersRequest) LeaderNotAvailableException(org.apache.kafka.common.errors.LeaderNotAvailableException) ApiError(org.apache.kafka.common.requests.ApiError) ConfigResource(org.apache.kafka.common.config.ConfigResource) OffsetOutOfRangeException(org.apache.kafka.common.errors.OffsetOutOfRangeException) MetadataRequest(org.apache.kafka.common.requests.MetadataRequest) AclBinding(org.apache.kafka.common.acl.AclBinding) OffsetDeleteResponseTopic(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopic) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity) ApiVersion(org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion) OngoingTopicReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingTopicReassignment) ConsumerPartitionAssignor(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor) Utils(org.apache.kafka.common.utils.Utils) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) TimeUnit(java.util.concurrent.TimeUnit) AlterPartitionReassignmentsResponseData(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData) DeleteTopicsResponse(org.apache.kafka.common.requests.DeleteTopicsResponse) MetadataResponseData(org.apache.kafka.common.message.MetadataResponseData) OffsetDeleteResponse(org.apache.kafka.common.requests.OffsetDeleteResponse) DescribeLogDirsResponse(org.apache.kafka.common.requests.DescribeLogDirsResponse) Timeout(org.junit.jupiter.api.Timeout) Collections(java.util.Collections) ApiException(org.apache.kafka.common.errors.ApiException) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) LeaveGroupResponseData(org.apache.kafka.common.message.LeaveGroupResponseData) TopicPartition(org.apache.kafka.common.TopicPartition) DescribeGroupsResponseData(org.apache.kafka.common.message.DescribeGroupsResponseData) DescribeGroupsResponse(org.apache.kafka.common.requests.DescribeGroupsResponse) KafkaException(org.apache.kafka.common.KafkaException) ExecutionException(java.util.concurrent.ExecutionException) UnknownMemberIdException(org.apache.kafka.common.errors.UnknownMemberIdException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 54 with Arrays.asList

use of java.util.Arrays.asList in project kafka by apache.

the class MemoryRecordsBuilderTest method testWriteLeaderChangeControlBatch.

@ParameterizedTest
@ArgumentsSource(MemoryRecordsBuilderArgumentsProvider.class)
public void testWriteLeaderChangeControlBatch(Args args) {
    ByteBuffer buffer = allocateBuffer(128, args);
    final int leaderId = 1;
    final int leaderEpoch = 5;
    final List<Integer> voters = Arrays.asList(2, 3);
    Supplier<MemoryRecordsBuilder> supplier = () -> new MemoryRecordsBuilder(buffer, args.magic, args.compressionType, TimestampType.CREATE_TIME, 0L, 0L, RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_EPOCH, RecordBatch.NO_SEQUENCE, false, true, leaderEpoch, buffer.capacity());
    if (args.magic < MAGIC_VALUE_V2) {
        assertThrows(IllegalArgumentException.class, supplier::get);
    } else {
        MemoryRecordsBuilder builder = supplier.get();
        builder.appendLeaderChangeMessage(RecordBatch.NO_TIMESTAMP, new LeaderChangeMessage().setLeaderId(leaderId).setVoters(voters.stream().map(voterId -> new Voter().setVoterId(voterId)).collect(Collectors.toList())));
        MemoryRecords built = builder.build();
        List<Record> records = TestUtils.toList(built.records());
        assertEquals(1, records.size());
        LeaderChangeMessage leaderChangeMessage = ControlRecordUtils.deserializeLeaderChangeMessage(records.get(0));
        assertEquals(leaderId, leaderChangeMessage.leaderId());
        assertEquals(voters, leaderChangeMessage.voters().stream().map(Voter::voterId).collect(Collectors.toList()));
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) MAGIC_VALUE_V2(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V2) MAGIC_VALUE_V1(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V1) BiFunction(java.util.function.BiFunction) EnumSource(org.junit.jupiter.params.provider.EnumSource) Random(java.util.Random) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) MAGIC_VALUE_V0(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0) Supplier(java.util.function.Supplier) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BufferSupplier(org.apache.kafka.common.utils.BufferSupplier) Arrays.asList(java.util.Arrays.asList) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LeaderChangeMessage(org.apache.kafka.common.message.LeaderChangeMessage) Utils(org.apache.kafka.common.utils.Utils) Time(org.apache.kafka.common.utils.Time) TestUtils(org.apache.kafka.test.TestUtils) Utils.utf8(org.apache.kafka.common.utils.Utils.utf8) Voter(org.apache.kafka.common.message.LeaderChangeMessage.Voter) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) CloseableIterator(org.apache.kafka.common.utils.CloseableIterator) Test(org.junit.jupiter.api.Test) UnsupportedCompressionTypeException(org.apache.kafka.common.errors.UnsupportedCompressionTypeException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ByteBufferOutputStream(org.apache.kafka.common.utils.ByteBufferOutputStream) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Collections(java.util.Collections) ByteBuffer(java.nio.ByteBuffer) LeaderChangeMessage(org.apache.kafka.common.message.LeaderChangeMessage) Voter(org.apache.kafka.common.message.LeaderChangeMessage.Voter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 55 with Arrays.asList

use of java.util.Arrays.asList in project kafka by apache.

the class MemoryRecordsBuilderTest method testUnsupportedCompress.

@Test
public void testUnsupportedCompress() {
    BiFunction<Byte, CompressionType, MemoryRecordsBuilder> builderBiFunction = (magic, compressionType) -> new MemoryRecordsBuilder(ByteBuffer.allocate(128), magic, compressionType, TimestampType.CREATE_TIME, 0L, 0L, RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_EPOCH, RecordBatch.NO_SEQUENCE, false, false, RecordBatch.NO_PARTITION_LEADER_EPOCH, 128);
    Arrays.asList(MAGIC_VALUE_V0, MAGIC_VALUE_V1).forEach(magic -> {
        Exception e = assertThrows(IllegalArgumentException.class, () -> builderBiFunction.apply(magic, CompressionType.ZSTD));
        assertEquals(e.getMessage(), "ZStandard compression is not supported for magic " + magic);
    });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) MAGIC_VALUE_V2(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V2) MAGIC_VALUE_V1(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V1) BiFunction(java.util.function.BiFunction) EnumSource(org.junit.jupiter.params.provider.EnumSource) Random(java.util.Random) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) MAGIC_VALUE_V0(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0) Supplier(java.util.function.Supplier) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BufferSupplier(org.apache.kafka.common.utils.BufferSupplier) Arrays.asList(java.util.Arrays.asList) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LeaderChangeMessage(org.apache.kafka.common.message.LeaderChangeMessage) Utils(org.apache.kafka.common.utils.Utils) Time(org.apache.kafka.common.utils.Time) TestUtils(org.apache.kafka.test.TestUtils) Utils.utf8(org.apache.kafka.common.utils.Utils.utf8) Voter(org.apache.kafka.common.message.LeaderChangeMessage.Voter) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) CloseableIterator(org.apache.kafka.common.utils.CloseableIterator) Test(org.junit.jupiter.api.Test) UnsupportedCompressionTypeException(org.apache.kafka.common.errors.UnsupportedCompressionTypeException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ByteBufferOutputStream(org.apache.kafka.common.utils.ByteBufferOutputStream) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Collections(java.util.Collections) UnsupportedCompressionTypeException(org.apache.kafka.common.errors.UnsupportedCompressionTypeException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Arrays.asList (java.util.Arrays.asList)65 List (java.util.List)61 ArrayList (java.util.ArrayList)48 Test (org.junit.Test)32 Arrays (java.util.Arrays)19 Collections.singletonList (java.util.Collections.singletonList)18 Map (java.util.Map)15 Test (org.junit.jupiter.api.Test)15 HashMap (java.util.HashMap)14 Collection (java.util.Collection)12 Collectors (java.util.stream.Collectors)12 Method (java.lang.reflect.Method)9 Optional (java.util.Optional)9 Collections.emptyList (java.util.Collections.emptyList)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Collections (java.util.Collections)7 Employee (com.artezio.arttime.datamodel.Employee)6 HourType (com.artezio.arttime.datamodel.HourType)6 Hours (com.artezio.arttime.datamodel.Hours)6 Project (com.artezio.arttime.datamodel.Project)6