1717% % create_topics
1818% % delete_topics
1919% % delete_records
20+ % % describe_configs
21+ % % alter_configs
2022-module (kpro_topic_mngr_tests ).
2123
2224-include_lib (" eunit/include/eunit.hrl" ).
2325-include (" kpro_private.hrl" ).
2426
27+ -define (RESOURCE_TYPE_TOPIC , 2 ).
28+
2529% % Create a random-name partition with 1 partition 1 replica
2630% % Increase partition number to 2
2731create_topic_partition_test () ->
@@ -68,6 +72,59 @@ test_create_topic_partition(CreateTopicsVsn, CreatePartitionsVsn) ->
6872 end
6973 end ).
7074
75+ % % Get all configurations for a topic.
76+ describe_configs_test () ->
77+ Vsn = get_max_api_vsn (describe_configs ),
78+ test_describe_configs (Vsn ).
79+
80+ test_describe_configs (false ) ->
81+ io :format (user , " skipped " , []);
82+ test_describe_configs (Vsn ) ->
83+ {ok , [Topic | _ ]} = get_test_topics (),
84+ DescribeConfigArgs =
85+ #{ resource_type => ? RESOURCE_TYPE_TOPIC
86+ , resource_name => Topic
87+ , config_names => ? null % % Get all configs
88+ },
89+ Opts = #{include_synonyms => false },
90+ Req = kpro_req_lib :describe_configs (Vsn , [DescribeConfigArgs ], Opts ),
91+ kpro_test_lib :with_connection (
92+ fun (Endpoints , Config ) -> kpro :connect_controller (Endpoints , Config ) end ,
93+ fun (Conn ) ->
94+ {ok , Rsp } = kpro :request_sync (Conn , Req , infinity ),
95+ Resources = kpro_test_lib :parse_rsp (Rsp ),
96+ ? assertMatch ([#{ resource_name := Topic }], Resources )
97+ end ).
98+
99+ % % Alter the configuration for a topic.
100+ alter_configs_test () ->
101+ Vsn = get_max_api_vsn (alter_configs ),
102+ test_alter_configs (Vsn ).
103+
104+ test_alter_configs (false ) ->
105+ io :format (user , " skipped " , []);
106+ test_alter_configs (Vsn ) ->
107+ {ok , [Topic | _ ]} = get_test_topics (),
108+ AlterConfigsArgs =
109+ #{ resource_type => ? RESOURCE_TYPE_TOPIC
110+ , resource_name => Topic
111+ , config_entries => [
112+ [ {config_name , " cleanup.policy" }
113+ , {config_value , <<" compact" >>}]
114+ ]
115+ },
116+ Opts = #{validate_only => false },
117+ Req = kpro_req_lib :alter_configs (Vsn , [AlterConfigsArgs ], Opts ),
118+ DescribeVsn = get_max_api_vsn (describe_configs ),
119+ kpro_test_lib :with_connection (
120+ fun (Endpoints , Config ) -> kpro :connect_controller (Endpoints , Config ) end ,
121+ fun (Conn ) ->
122+ validate_topic_config (DescribeVsn , Conn , Topic , " cleanup.policy" , <<" delete" >>),
123+ {ok , Rsp } = kpro :request_sync (Conn , Req , infinity ),
124+ ok = kpro_test_lib :parse_rsp (Rsp ),
125+ validate_topic_config (DescribeVsn , Conn , Topic , " cleanup.policy" , <<" compact" >>)
126+ end ).
127+
71128% % Delete all topics created in this test module.
72129delete_topics_test () ->
73130 Timeout = case is_integer (get_max_api_vsn (create_partitions )) of
@@ -119,7 +176,7 @@ get_test_topics(Connection) ->
119176 ErrorCode = ? no_error , % % assert
120177 Name = kpro :find (topic , Topic ),
121178 case lists :prefix (atom_to_list (? MODULE ),
122- binary_to_list (Name )) of
179+ binary_to_list (Name )) of
123180 true -> [Name | Acc ];
124181 false -> Acc
125182 end
@@ -141,6 +198,20 @@ get_max_api_vsn(API) ->
141198
142199rand () -> rand :uniform (1000000 ).
143200
201+ validate_topic_config (false , _ , _ , _ , _ ) ->
202+ not_available ;
203+ validate_topic_config (Vsn , Conn , Topic , ConfigName , ConfigValue ) ->
204+ DescribeConfigArgs =
205+ #{ resource_type => ? RESOURCE_TYPE_TOPIC
206+ , resource_name => Topic
207+ , config_names => [ConfigName ]
208+ },
209+ Req = kpro_req_lib :describe_configs (Vsn , [DescribeConfigArgs ], #{}),
210+ {ok , Rsp } = kpro :request_sync (Conn , Req , infinity ),
211+ [Resource ] = kpro_test_lib :parse_rsp (Rsp ),
212+ [Entry ] = kpro :find (config_entries , Resource ),
213+ ? assertEqual (ConfigValue , kpro :find (config_value , Entry )).
214+
144215% %%_* Emacs ====================================================================
145216% %% Local Variables:
146217% %% allout-layout: t
0 commit comments