Skip to content

Commit b3fd72c

Browse files
committed
Updated the KafkaEvent header(s) value to use the correct array type of sbyte values, so that negative values could be handled.
1 parent 15aff3d commit b3fd72c

File tree

4 files changed

+179
-6
lines changed

4 files changed

+179
-6
lines changed

Libraries/src/Amazon.Lambda.KafkaEvents/Amazon.Lambda.KafkaEvents.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<TargetFrameworks>netstandard2.0</TargetFrameworks>
77
<Description>Amazon Lambda .NET Core support - KafkaEvents package.</Description>
88
<AssemblyTitle>Amazon.Lambda.KafkaEvents</AssemblyTitle>
9-
<VersionPrefix>1.0.1</VersionPrefix>
9+
<VersionPrefix>2.0.0</VersionPrefix>
1010
<AssemblyName>Amazon.Lambda.KafkaEvents</AssemblyName>
1111
<PackageId>Amazon.Lambda.KafkaEvents</PackageId>
1212
<PackageTags>AWS;Amazon;Lambda;Kafka</PackageTags>

Libraries/src/Amazon.Lambda.KafkaEvents/KafkaEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class KafkaEventRecord
7373
/// <summary>
7474
/// The Kafka event record headers.
7575
/// </summary>
76-
public IList<IDictionary<string, byte[]>> Headers { get; set; }
76+
public IList<IDictionary<string, sbyte[]>> Headers { get; set; }
7777
}
7878
}
7979
}

Libraries/test/EventsTests.Shared/EventTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,20 +2729,25 @@ public void KafkaEventTest(Type serializerType)
27292729
var eventRecord = record.Value.FirstOrDefault();
27302730
Assert.Equal(eventRecord.Topic, "mytopic");
27312731
Assert.Equal(eventRecord.Partition, 12);
2732-
Assert.Equal(eventRecord.Offset, 15);
2732+
Assert.Equal(eventRecord.Offset, 3043205);
27332733
Assert.Equal(eventRecord.Timestamp, 1545084650987);
27342734
Assert.Equal(eventRecord.TimestampType, "CREATE_TIME");
27352735

27362736
Assert.Equal(new StreamReader(eventRecord.Value).ReadToEnd(), "Hello, this is a test.");
27372737

2738-
Assert.Equal(eventRecord.Headers.Count, 1);
2738+
Assert.Equal(eventRecord.Headers.Count, 8);
27392739
var eventRecordHeader = eventRecord.Headers.FirstOrDefault();
27402740
Assert.NotNull(eventRecordHeader);
27412741
Assert.Equal(eventRecordHeader.Count, 1);
27422742
var eventRecordHeaderValue = eventRecordHeader.FirstOrDefault();
27432743
Assert.NotNull(eventRecordHeaderValue);
27442744
Assert.Equal(eventRecordHeaderValue.Key, "headerKey");
2745-
Assert.Equal(Encoding.UTF8.GetString(eventRecordHeaderValue.Value), "headerValue");
2745+
2746+
// Convert sbyte[] to byte[] array.
2747+
var tempHeaderValueByteArray = new byte[eventRecordHeaderValue.Value.Length];
2748+
Buffer.BlockCopy(eventRecordHeaderValue.Value, 0, tempHeaderValueByteArray, 0, tempHeaderValueByteArray.Length);
2749+
2750+
Assert.Equal(Encoding.UTF8.GetString(tempHeaderValueByteArray), "headerValue");
27462751

27472752
Handle(kafkaEvent);
27482753
}

Libraries/test/EventsTests.Shared/kafka-event.json

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
{
88
"topic": "mytopic",
99
"partition": 12,
10-
"offset": 15,
10+
"offset": 3043205,
1111
"timestamp": 1545084650987,
1212
"timestampType": "CREATE_TIME",
13+
"key": "MzM4NjQ2Njcy",
1314
"value": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0Lg==",
1415
"headers": [
1516
{
@@ -26,6 +27,173 @@
2627
117,
2728
101
2829
]
30+
},
31+
{
32+
"Id": [
33+
55,
34+
48,
35+
57,
36+
101,
37+
52,
38+
57,
39+
98,
40+
54,
41+
45,
42+
57,
43+
57,
44+
56,
45+
100,
46+
45,
47+
52,
48+
99,
49+
48,
50+
99,
51+
45,
52+
56,
53+
101,
54+
102,
55+
55,
56+
45,
57+
98,
58+
57,
59+
56,
60+
99,
61+
102,
62+
97,
63+
102,
64+
101,
65+
100,
66+
48,
67+
56,
68+
98
69+
]
70+
},
71+
{
72+
"ModelType": [
73+
82,
74+
101,
75+
115,
76+
105,
77+
100,
78+
101,
79+
110,
80+
116,
81+
105,
82+
97,
83+
108,
84+
80,
85+
114,
86+
111,
87+
100,
88+
117,
89+
99,
90+
116,
91+
95,
92+
65,
93+
103,
94+
101,
95+
110,
96+
116,
97+
68,
98+
101,
99+
116,
100+
97,
101+
105,
102+
108
103+
]
104+
},
105+
{
106+
"Version": [
107+
0,
108+
0,
109+
0,
110+
0,
111+
0,
112+
0,
113+
0,
114+
3
115+
]
116+
},
117+
{
118+
"IsFullBuild": [
119+
1
120+
]
121+
},
122+
{
123+
"IsLowPriority": [
124+
1
125+
]
126+
},
127+
{
128+
"OriginationTimestamp": [
129+
0,
130+
0,
131+
1,
132+
-123,
133+
-11,
134+
-81,
135+
-50,
136+
-2
137+
]
138+
},
139+
{
140+
"traceparent": [
141+
48,
142+
48,
143+
45,
144+
54,
145+
57,
146+
49,
147+
99,
148+
99,
149+
101,
150+
55,
151+
50,
152+
102,
153+
50,
154+
55,
155+
52,
156+
97,
157+
54,
158+
100,
159+
54,
160+
56,
161+
97,
162+
102,
163+
54,
164+
54,
165+
56,
166+
102,
167+
54,
168+
51,
169+
97,
170+
98,
171+
52,
172+
97,
173+
57,
174+
99,
175+
49,
176+
45,
177+
53,
178+
97,
179+
97,
180+
50,
181+
57,
182+
98,
183+
54,
184+
99,
185+
97,
186+
51,
187+
97,
188+
49,
189+
101,
190+
57,
191+
50,
192+
102,
193+
45,
194+
48,
195+
48
196+
]
29197
}
30198
]
31199
}

0 commit comments

Comments
 (0)