@@ -30,8 +30,9 @@ import org.apache.kafka.common.protocol.Errors
30
30
import org .apache .kafka .common .record ._
31
31
import org .apache .kafka .common .requests .OffsetFetchResponse
32
32
import org .apache .kafka .common .requests .ProduceResponse .PartitionResponse
33
+ import org .apache .kafka .common .KafkaException
33
34
import org .easymock .{Capture , EasyMock , IAnswer }
34
- import org .junit .Assert .{assertEquals , assertFalse , assertNull , assertTrue }
35
+ import org .junit .Assert .{assertEquals , assertFalse , assertNull , assertTrue , assertThrows }
35
36
import org .junit .{Before , Test }
36
37
import org .scalatest .Assertions .fail
37
38
import java .nio .ByteBuffer
@@ -802,7 +803,45 @@ class GroupMetadataManagerTest {
802
803
}
803
804
804
805
@ Test
805
- def testReadFromOldGroupMetadata () {
806
+ def testShouldThrowExceptionForUnsupportedGroupMetadataVersion (): Unit = {
807
+ val generation = 1
808
+ val protocol = " range"
809
+ val memberId = " memberId"
810
+ val unsupportedVersion = Short .MinValue
811
+
812
+ // put the unsupported version as the version value
813
+ val groupMetadataRecordValue = buildStableGroupRecordWithMember(generation, protocolType, protocol, memberId)
814
+ .value().putShort(unsupportedVersion)
815
+ // reset the position to the starting position 0 so that it can read the data in correct order
816
+ groupMetadataRecordValue.position(0 )
817
+
818
+ val e = assertThrows(classOf [KafkaException ],
819
+ () => GroupMetadataManager .readGroupMessageValue(groupId, groupMetadataRecordValue, time))
820
+ assertEquals(s " Unknown group metadata version ${unsupportedVersion}" , e.getMessage)
821
+ }
822
+
823
+ @ Test
824
+ def testCurrentStateTimestampForAllGroupMetadataVersions (): Unit = {
825
+ val generation = 1
826
+ val protocol = " range"
827
+ val memberId = " memberId"
828
+
829
+ for (apiVersion <- ApiVersion .allVersions) {
830
+ val groupMetadataRecord = buildStableGroupRecordWithMember(generation, protocolType, protocol, memberId, apiVersion = apiVersion)
831
+
832
+ val deserializedGroupMetadata = GroupMetadataManager .readGroupMessageValue(groupId, groupMetadataRecord.value(), time)
833
+ // GROUP_METADATA_VALUE_SCHEMA_V2 or higher should correctly set the currentStateTimestamp
834
+ if (apiVersion >= KAFKA_2_1_IV0 )
835
+ assertEquals(s " the apiVersion $apiVersion doesn't set the currentStateTimestamp correctly. " ,
836
+ Some (time.milliseconds()), deserializedGroupMetadata.currentStateTimestamp)
837
+ else
838
+ assertTrue(s " the apiVersion $apiVersion should not set the currentStateTimestamp. " ,
839
+ deserializedGroupMetadata.currentStateTimestamp.isEmpty)
840
+ }
841
+ }
842
+
843
+ @ Test
844
+ def testReadFromOldGroupMetadata (): Unit = {
806
845
val generation = 1
807
846
val protocol = " range"
808
847
val memberId = " memberId"
0 commit comments