From f2dd5b06fe7ba39fd886d86b8c49c306dfbc2024 Mon Sep 17 00:00:00 2001 From: dingshuangxi888 Date: Wed, 20 Mar 2024 14:38:01 +0800 Subject: [PATCH] [ISSUE #7943] Add bazel config for auth module and fix bazel test (#7944) --- auth/BUILD.bazel | 77 +++++++++++++++++++ .../AuthenticationMetadataManagerImpl.java | 2 +- .../LocalAuthenticationMetadataProvider.java | 3 +- .../LocalAuthorizationMetadataProvider.java | 3 +- .../rocketmq/auth/migration/AuthMigrator.java | 4 +- ...faultAuthenticationContextBuilderTest.java | 3 +- ...efaultAuthorizationContextBuilderTest.java | 3 +- broker/BUILD.bazel | 4 + .../rocketmq/client/impl/MQAdminImpl.java | 6 +- common/BUILD.bazel | 6 ++ proxy/BUILD.bazel | 6 +- remoting/BUILD.bazel | 2 + tieredstore/BUILD.bazel | 4 +- .../file/FlatConsumeQueueFileTest.java | 21 ----- .../provider/PosixFileSegmentTest.java | 21 ----- 15 files changed, 107 insertions(+), 58 deletions(-) create mode 100644 auth/BUILD.bazel delete mode 100644 tieredstore/src/test/java/org/apache/rocketmq/tieredstore/file/FlatConsumeQueueFileTest.java delete mode 100644 tieredstore/src/test/java/org/apache/rocketmq/tieredstore/provider/PosixFileSegmentTest.java diff --git a/auth/BUILD.bazel b/auth/BUILD.bazel new file mode 100644 index 0000000000..44dd8bad8b --- /dev/null +++ b/auth/BUILD.bazel @@ -0,0 +1,77 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +load("//bazel:GenTestRules.bzl", "GenTestRules") + +java_library( + name = "auth", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//acl", + "//common", + "//remoting", + "//srvutil", + "@maven//:commons_codec_commons_codec", + "@maven//:org_apache_commons_commons_lang3", + "@maven//:commons_collections_commons_collections", + "@maven//:com_alibaba_fastjson2_fastjson2", + "@maven//:org_apache_rocketmq_rocketmq_proto", + "@maven//:org_slf4j_slf4j_api", + "@maven//:com_github_ben_manes_caffeine_caffeine", + "@maven//:io_grpc_grpc_api", + "@maven//:com_google_protobuf_protobuf_java", + "@maven//:com_google_protobuf_protobuf_java_util", + "@maven//:io_netty_netty_all", + "@maven//:com_google_guava_guava", + "@maven//:org_apache_rocketmq_rocketmq_rocksdb", + ], +) + +java_library( + name = "tests", + srcs = glob(["src/test/java/**/*.java"]), + resources = glob(["src/test/resources/**/*.yml"]), + visibility = ["//visibility:public"], + deps = [ + ":auth", + "//acl", + "//:test_deps", + "//common", + "//remoting", + "@maven//:commons_codec_commons_codec", + "@maven//:org_apache_commons_commons_lang3", + "@maven//:commons_collections_commons_collections", + "@maven//:com_alibaba_fastjson2_fastjson2", + "@maven//:org_apache_rocketmq_rocketmq_proto", + "@maven//:org_slf4j_slf4j_api", + "@maven//:com_github_ben_manes_caffeine_caffeine", + "@maven//:io_grpc_grpc_api", + "@maven//:com_google_protobuf_protobuf_java", + "@maven//:com_google_protobuf_protobuf_java_util", + "@maven//:io_netty_netty_all", + "@maven//:com_google_guava_guava", + "@maven//:org_apache_rocketmq_rocketmq_rocksdb", + ], +) + +GenTestRules( + name = "GeneratedTestRules", + test_files = glob(["src/test/java/**/*Test.java"]), + deps = [ + ":tests", + ], +) diff --git a/auth/src/main/java/org/apache/rocketmq/auth/authentication/manager/AuthenticationMetadataManagerImpl.java b/auth/src/main/java/org/apache/rocketmq/auth/authentication/manager/AuthenticationMetadataManagerImpl.java index 5feabe8a65..3634a10cb8 100644 --- a/auth/src/main/java/org/apache/rocketmq/auth/authentication/manager/AuthenticationMetadataManagerImpl.java +++ b/auth/src/main/java/org/apache/rocketmq/auth/authentication/manager/AuthenticationMetadataManagerImpl.java @@ -16,7 +16,7 @@ */ package org.apache.rocketmq.auth.authentication.manager; -import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson2.JSON; import java.util.List; import java.util.concurrent.CompletableFuture; import org.apache.commons.lang3.StringUtils; diff --git a/auth/src/main/java/org/apache/rocketmq/auth/authentication/provider/LocalAuthenticationMetadataProvider.java b/auth/src/main/java/org/apache/rocketmq/auth/authentication/provider/LocalAuthenticationMetadataProvider.java index 6832102f57..dcf9061822 100644 --- a/auth/src/main/java/org/apache/rocketmq/auth/authentication/provider/LocalAuthenticationMetadataProvider.java +++ b/auth/src/main/java/org/apache/rocketmq/auth/authentication/provider/LocalAuthenticationMetadataProvider.java @@ -35,7 +35,6 @@ import org.apache.rocketmq.auth.authentication.model.User; import org.apache.rocketmq.auth.config.AuthConfig; import org.apache.rocketmq.common.config.ConfigRocksDBStorage; import org.apache.rocketmq.common.thread.ThreadPoolMonitor; -import org.checkerframework.checker.nullness.qual.NonNull; import org.rocksdb.RocksIterator; public class LocalAuthenticationMetadataProvider implements AuthenticationMetadataProvider { @@ -152,7 +151,7 @@ public class LocalAuthenticationMetadataProvider implements AuthenticationMetada } @Override - public User load(@NonNull String username) { + public User load(String username) { try { byte[] keyBytes = username.getBytes(StandardCharsets.UTF_8); byte[] valueBytes = storage.get(keyBytes); diff --git a/auth/src/main/java/org/apache/rocketmq/auth/authorization/provider/LocalAuthorizationMetadataProvider.java b/auth/src/main/java/org/apache/rocketmq/auth/authorization/provider/LocalAuthorizationMetadataProvider.java index b698444ac3..bc63178108 100644 --- a/auth/src/main/java/org/apache/rocketmq/auth/authorization/provider/LocalAuthorizationMetadataProvider.java +++ b/auth/src/main/java/org/apache/rocketmq/auth/authorization/provider/LocalAuthorizationMetadataProvider.java @@ -40,7 +40,6 @@ import org.apache.rocketmq.auth.authorization.model.PolicyEntry; import org.apache.rocketmq.auth.config.AuthConfig; import org.apache.rocketmq.common.config.ConfigRocksDBStorage; import org.apache.rocketmq.common.thread.ThreadPoolMonitor; -import org.checkerframework.checker.nullness.qual.NonNull; import org.rocksdb.RocksIterator; public class LocalAuthorizationMetadataProvider implements AuthorizationMetadataProvider { @@ -181,7 +180,7 @@ public class LocalAuthorizationMetadataProvider implements AuthorizationMetadata } @Override - public Acl load(@NonNull String subjectKey) { + public Acl load(String subjectKey) { try { byte[] keyBytes = subjectKey.getBytes(StandardCharsets.UTF_8); Subject subject = Subject.of(subjectKey); diff --git a/auth/src/main/java/org/apache/rocketmq/auth/migration/AuthMigrator.java b/auth/src/main/java/org/apache/rocketmq/auth/migration/AuthMigrator.java index f2e4f7a65f..5229ce1688 100644 --- a/auth/src/main/java/org/apache/rocketmq/auth/migration/AuthMigrator.java +++ b/auth/src/main/java/org/apache/rocketmq/auth/migration/AuthMigrator.java @@ -45,8 +45,8 @@ import org.apache.rocketmq.common.constant.CommonConstants; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.resource.ResourcePattern; import org.apache.rocketmq.common.resource.ResourceType; -import org.apache.rocketmq.logging.org.slf4j.Logger; -import org.apache.rocketmq.logging.org.slf4j.LoggerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class AuthMigrator { diff --git a/auth/src/test/java/org/apache/rocketmq/auth/authentication/builder/DefaultAuthenticationContextBuilderTest.java b/auth/src/test/java/org/apache/rocketmq/auth/authentication/builder/DefaultAuthenticationContextBuilderTest.java index 00f17c1459..e8e0144fcb 100644 --- a/auth/src/test/java/org/apache/rocketmq/auth/authentication/builder/DefaultAuthenticationContextBuilderTest.java +++ b/auth/src/test/java/org/apache/rocketmq/auth/authentication/builder/DefaultAuthenticationContextBuilderTest.java @@ -30,7 +30,6 @@ import org.apache.rocketmq.common.constant.GrpcConstants; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RequestCode; import org.apache.rocketmq.remoting.protocol.header.SendMessageRequestHeader; -import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -110,7 +109,7 @@ public class DefaultAuthenticationContextBuilderTest { } @Override - public int compareTo(@NotNull ChannelId o) { + public int compareTo(ChannelId o) { return 0; } }; diff --git a/auth/src/test/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilderTest.java b/auth/src/test/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilderTest.java index 7ba6c48f5c..4ee73f3d79 100644 --- a/auth/src/test/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilderTest.java +++ b/auth/src/test/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilderTest.java @@ -72,7 +72,6 @@ import org.apache.rocketmq.remoting.protocol.header.UpdateConsumerOffsetRequestH import org.apache.rocketmq.remoting.protocol.heartbeat.ConsumerData; import org.apache.rocketmq.remoting.protocol.heartbeat.HeartbeatData; import org.apache.rocketmq.remoting.protocol.heartbeat.SubscriptionData; -import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -499,7 +498,7 @@ public class DefaultAuthorizationContextBuilderTest { } @Override - public int compareTo(@NotNull ChannelId o) { + public int compareTo(ChannelId o) { return 0; } }; diff --git a/broker/BUILD.bazel b/broker/BUILD.bazel index ab413d3d06..b2ee2549bc 100644 --- a/broker/BUILD.bazel +++ b/broker/BUILD.bazel @@ -22,6 +22,7 @@ java_library( visibility = ["//visibility:public"], deps = [ "//acl", + "//auth", "//client", "//common", "//filter", @@ -30,6 +31,7 @@ java_library( "//store", "@maven//:ch_qos_logback_logback_classic", "@maven//:com_alibaba_fastjson", + "@maven//:com_alibaba_fastjson2_fastjson2", "@maven//:com_github_luben_zstd_jni", "@maven//:com_google_guava_guava", "@maven//:com_googlecode_concurrentlinkedhashmap_concurrentlinkedhashmap_lru", @@ -73,12 +75,14 @@ java_library( ":broker", "//:test_deps", "//acl", + "//auth", "//client", "//common", "//filter", "//remoting", "//store", "@maven//:com_alibaba_fastjson", + "@maven//:com_alibaba_fastjson2_fastjson2", "@maven//:com_google_guava_guava", "@maven//:io_netty_netty_all", "@maven//:org_apache_commons_commons_lang3", diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java index dd64571e4a..b1d07b85f7 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java @@ -264,11 +264,11 @@ public class MQAdminImpl { public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { - MessageId messageId = null; + MessageId messageId; try { messageId = MessageDecoder.decodeMessageId(msgId); - return this.mQClientFactory.getMQAdminImpl().viewMessage(topic, msgId); - } catch (Exception ignored) { + } catch (Exception e) { + throw new MQClientException(ResponseCode.NO_MESSAGE, "query message by id finished, but no message."); } return this.mQClientFactory.getMQClientAPIImpl().viewMessage(NetworkUtil.socketAddress2String(messageId.getAddress()), topic, messageId.getOffset(), timeoutMillis); diff --git a/common/BUILD.bazel b/common/BUILD.bazel index 9a0c31e772..dc135504f3 100644 --- a/common/BUILD.bazel +++ b/common/BUILD.bazel @@ -22,6 +22,7 @@ java_library( visibility = ["//visibility:public"], deps = [ "@maven//:com_alibaba_fastjson", + "@maven//:com_alibaba_fastjson2_fastjson2", "@maven//:com_github_luben_zstd_jni", "@maven//:com_google_guava_guava", "@maven//:commons_collections_commons_collections", @@ -36,6 +37,8 @@ java_library( "@maven//:io_opentelemetry_opentelemetry_sdk_common", "@maven//:io_opentelemetry_opentelemetry_sdk_metrics", "@maven//:io_opentelemetry_opentelemetry_exporter_logging_otlp", + "@maven//:io_grpc_grpc_api", + "@maven//:io_grpc_grpc_context", "@maven//:org_apache_commons_commons_lang3", "@maven//:org_lz4_lz4_java", "@maven//:io_github_aliyunmq_rocketmq_slf4j_api", @@ -53,6 +56,7 @@ java_library( "//:test_deps", "@maven//:com_google_guava_guava", "@maven//:com_alibaba_fastjson", + "@maven//:com_alibaba_fastjson2_fastjson2", "@maven//:io_netty_netty_all", "@maven//:io_opentelemetry_opentelemetry_api", "@maven//:io_opentelemetry_opentelemetry_context", @@ -61,6 +65,8 @@ java_library( "@maven//:io_opentelemetry_opentelemetry_sdk", "@maven//:io_opentelemetry_opentelemetry_sdk_common", "@maven//:io_opentelemetry_opentelemetry_sdk_metrics", + "@maven//:io_grpc_grpc_api", + "@maven//:io_grpc_grpc_context", "@maven//:org_apache_commons_commons_lang3", ], resources = glob(["src/test/resources/certs/*.pem"]) + glob(["src/test/resources/certs/*.key"]) diff --git a/proxy/BUILD.bazel b/proxy/BUILD.bazel index eb069528ea..b5a970bb0d 100644 --- a/proxy/BUILD.bazel +++ b/proxy/BUILD.bazel @@ -22,6 +22,7 @@ java_library( visibility = ["//visibility:public"], deps = [ "//acl", + "//auth", "//broker", "//client", "//common", @@ -30,6 +31,7 @@ java_library( "@maven//:ch_qos_logback_logback_classic", "@maven//:ch_qos_logback_logback_core", "@maven//:com_alibaba_fastjson", + "@maven//:com_alibaba_fastjson2_fastjson2", "@maven//:com_github_ben_manes_caffeine_caffeine", "@maven//:com_github_luben_zstd_jni", "@maven//:com_google_code_findbugs_jsr305", @@ -78,7 +80,8 @@ java_library( ], visibility = ["//visibility:public"], deps = [ - "//acl", + "//acl", + "//auth", ":proxy", "//:test_deps", "//broker", @@ -87,6 +90,7 @@ java_library( "//remoting", "@maven//:ch_qos_logback_logback_core", "@maven//:com_alibaba_fastjson", + "@maven//:com_alibaba_fastjson2_fastjson2", "@maven//:com_github_ben_manes_caffeine_caffeine", "@maven//:com_google_guava_guava", "@maven//:com_google_protobuf_protobuf_java", diff --git a/remoting/BUILD.bazel b/remoting/BUILD.bazel index 072148bc08..9f806be763 100644 --- a/remoting/BUILD.bazel +++ b/remoting/BUILD.bazel @@ -39,6 +39,7 @@ java_library( "@maven//:io_github_aliyunmq_rocketmq_slf4j_api", "@maven//:io_github_aliyunmq_rocketmq_logback_classic", "@maven//:commons_collections_commons_collections", + "@maven//:org_reflections_reflections", ], ) @@ -66,6 +67,7 @@ java_library( "@maven//:org_apache_tomcat_annotations_api", "@maven//:org_apache_commons_commons_lang3", "@maven//:org_jetbrains_annotations", + "@maven//:org_reflections_reflections", ], resources = glob(["src/test/resources/certs/*.pem"]) + glob(["src/test/resources/certs/*.key"]) ) diff --git a/tieredstore/BUILD.bazel b/tieredstore/BUILD.bazel index e16fca90d0..8822280ff8 100644 --- a/tieredstore/BUILD.bazel +++ b/tieredstore/BUILD.bazel @@ -42,6 +42,7 @@ java_library( "@maven//:com_alibaba_fastjson", "@maven//:org_apache_rocketmq_rocketmq_rocksdb", "@maven//:commons_collections_commons_collections", + "@maven//:org_slf4j_slf4j_api", ], ) @@ -68,8 +69,9 @@ java_library( "@maven//:org_apache_commons_commons_lang3", "@maven//:com_google_guava_guava", "@maven//:io_github_aliyunmq_rocketmq_slf4j_api", - "@maven//:io_github_aliyunmq_rocketmq_shaded_slf4j_api_bridge", + "@maven//:io_github_aliyunmq_rocketmq_logback_classic", "@maven//:net_java_dev_jna_jna", + "@maven//:org_slf4j_slf4j_api", ], ) diff --git a/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/file/FlatConsumeQueueFileTest.java b/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/file/FlatConsumeQueueFileTest.java deleted file mode 100644 index 8dfc1553d5..0000000000 --- a/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/file/FlatConsumeQueueFileTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.rocketmq.tieredstore.file; - -public class FlatConsumeQueueFileTest { - -} \ No newline at end of file diff --git a/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/provider/PosixFileSegmentTest.java b/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/provider/PosixFileSegmentTest.java deleted file mode 100644 index e74e46a543..0000000000 --- a/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/provider/PosixFileSegmentTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.rocketmq.tieredstore.provider; - -public class PosixFileSegmentTest { - -}