@@ -833,7 +833,10 @@ test_leader_restart() ->
833833 end ).
834834
835835with_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes , TestFunc ) ->
836- ok = create_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes ),
836+ with_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes , default_sgement_bytes , TestFunc ).
837+
838+ with_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes , SegmentBytes , TestFunc ) ->
839+ ok = create_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes , SegmentBytes ),
837840 try
838841 _ = application :stop (wolff ), % % ensure stopped
839842 {ok , _ } = application :ensure_all_started (wolff ),
@@ -842,23 +845,13 @@ with_topic(Topic, Partitions, ReplicationFactor, MaxMessageBytes, TestFunc) ->
842845 ok = delete_topic (Topic )
843846 end .
844847
845-
846- message_too_large_test_ () ->
847- {timeout , 60 ,
848- fun () -> test_message_too_large () end }.
849-
850- test_message_too_large () ->
851- Topic = " message-too-large-" ++ integer_to_list (abs (erlang :monotonic_time ())),
852- Partitions = 1 ,
853- ReplicationFactor = 1 ,
854- MaxMessageBytes = 100 ,
855- with_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes , fun () ->
848+ test_batch_split_then_drop (Topic , MaxMessageBytes ) ->
856849 ClientCfg = client_config (),
857850 ClientId = iolist_to_binary (" client-" ++ Topic ),
858851 {ok , Client } = start_client (ClientId , ? HOSTS , ClientCfg #{connection_strategy => per_partition }),
859852 TopicBin = iolist_to_binary (Topic ),
860853 % % try to batch more messages than Kafka's limit,
861- % % the producer will get message_too_large error back
854+ % % the producer will get message_too_large or record_list_too_large error back
862855 % % then it should retry sending one message at a time
863856 ProducerCfg = #{partitioner => fun (_ , _ ) -> 0 end ,
864857 max_batch_bytes => MaxMessageBytes * 3 ,
@@ -894,8 +887,38 @@ test_message_too_large() ->
894887 ? assertEqual (message_too_large , (SendFunc ([Msg (<<" 0123456789" >>)]))()),
895888 ok = wolff :stop_producers (Producers ),
896889 ok = stop_client (Client ),
897- ok = application :stop (wolff )
898- end ).
890+ ok = application :stop (wolff ).
891+
892+ % % Max message size is smaller than segment bytes to tigger record_list_too_large error.
893+ % % This is usually a bad server/topic configuration, but we need to cover it anyways.
894+ record_list_too_large_test_ () ->
895+ {timeout , 60 ,
896+ fun () -> test_record_list_too_large () end }.
897+
898+ test_record_list_too_large () ->
899+ Topic = " record-list-too-large-" ++ integer_to_list (abs (erlang :monotonic_time ())),
900+ Partitions = 1 ,
901+ ReplicationFactor = 1 ,
902+ MaxMessageBytes = 1000 ,
903+ SegmentBytes = 100 ,
904+ with_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes , SegmentBytes ,
905+ fun () ->
906+ test_batch_split_then_drop (Topic , SegmentBytes )
907+ end ).
908+
909+ message_too_large_test_ () ->
910+ {timeout , 60 ,
911+ fun () -> test_message_too_large () end }.
912+
913+ test_message_too_large () ->
914+ Topic = " message-too-large-" ++ integer_to_list (abs (erlang :monotonic_time ())),
915+ Partitions = 1 ,
916+ ReplicationFactor = 1 ,
917+ MaxMessageBytes = 100 ,
918+ with_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes ,
919+ fun () ->
920+ test_batch_split_then_drop (Topic , MaxMessageBytes )
921+ end ).
899922
900923one_byte_limit_test_ () ->
901924 {timeout , 10 , fun one_byte_limit /0 }.
@@ -1010,8 +1033,8 @@ encoded_bytes(Batch) ->
10101033 Encoded = kpro_batch :encode (2 , Batch , no_compression ),
10111034 iolist_size (Encoded ).
10121035
1013- create_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes ) ->
1014- Cmd = create_topic_cmd (Topic , Partitions , ReplicationFactor , MaxMessageBytes ),
1036+ create_topic (Topic , Partitions , ReplicationFactor , MaxMessageBytes , SegmentBytes ) ->
1037+ Cmd = create_topic_cmd (Topic , Partitions , ReplicationFactor , MaxMessageBytes , SegmentBytes ),
10151038 Result = os :cmd (Cmd ),
10161039 Pattern = " Created topic " ,
10171040 ? assert (string :str (Result , Pattern ) > 0 , Result ),
@@ -1020,7 +1043,7 @@ create_topic(Topic, Partitions, ReplicationFactor, MaxMessageBytes) ->
10201043delete_topic (Topic ) ->
10211044 wolff_test_utils :delete_topic (Topic ).
10221045
1023- create_topic_cmd (Topic , Partitions , ReplicationFactor , MaxMessageBytes ) ->
1046+ create_topic_cmd (Topic , Partitions , ReplicationFactor , MaxMessageBytes , SegmentBytes ) ->
10241047 wolff_test_utils :topics_cmd_base (Topic ) ++
10251048 " --create" ++
10261049 " --partitions " ++ integer_to_list (Partitions ) ++
@@ -1030,6 +1053,12 @@ create_topic_cmd(Topic, Partitions, ReplicationFactor, MaxMessageBytes) ->
10301053 " --config max.message.bytes=" ++ integer_to_list (MaxMessageBytes );
10311054 false ->
10321055 " "
1056+ end ++
1057+ case is_integer (SegmentBytes ) of
1058+ true ->
1059+ " --config segment.bytes=" ++ integer_to_list (SegmentBytes );
1060+ false ->
1061+ " "
10331062 end .
10341063
10351064stop_kafka_2 () ->
0 commit comments