Skip to content

Commit

Permalink
Add eventId field to B2EventNotificationEvent (#81) (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlcox authored Jul 16, 2024
1 parent 412f227 commit 7b7ee3d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
19 changes: 12 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog
## [Unreleased] - TBD
### Added
* Added `eventId` field to `B2EventNotificationEvent`.

### [6.2.0] - 2024-04-15
## [6.2.0] - 2024-04-15
### Added
* Added support to specify B2Json union types using annotations. Annotation support for union types is required because
Java records do not support inheritance. Example usage:
```java
Expand All @@ -28,20 +31,22 @@
@B2Json.type
record Point(@B2Json.required int x, @B2Json.required int y) { }
```
* Optimized B2DateTimeUtil.formatFguidDateTime
* Reduced memory allocation for small input when deserializing byte[] to JSON
* Reduced lock contention in B2Clock
* Added support for B2 Event Notifications
* Added B2Json `fromJson` methods that take a `java.io.Reader` as input for JSON
* Updated B2Json `fromJson` methods to utilize a BufferedReader when deserializing JSON for performance improvement
* Added B2StorageClient.storePartsForLargeFile
* Added support for daysFromStartingToCancelingUnfinishedLargeFiles to B2LifecycleRule
* Reduced lock contention in B2AccountAuthorizationCache
* Added the `serializedName` annotation to rename the serialized Json member name
* Added support for AtomicLongArray in B2Json
* Added support for custom upload timestamps

### Changed
* Optimized `B2DateTimeUtil.formatFguidDateTime`
* Reduced memory allocation for small input when deserializing byte[] to JSON
* Reduced lock contention in B2Clock
* Updated B2Json `fromJson` methods to utilize a BufferedReader when deserializing JSON for performance improvement
* Reduced lock contention in B2AccountAuthorizationCache
* Reduced lock contention in B2Json
* Updated internal python for building to python3
* Added support for custom upload timestamps

### Fixed
* Fixed union types to ignore extra and discarded fields when deserializing JSON to Java objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class B2EventNotificationEvent {
@B2Json.required
private final String eventType;
@B2Json.required
String eventId;
@B2Json.required
private final int eventVersion;
@B2Json.required
private final String matchedRuleName;
Expand All @@ -42,6 +44,7 @@ public B2EventNotificationEvent(String accountId,
String bucketName,
long eventTimestamp,
String eventType,
String eventId,
int eventVersion,
String matchedRuleName,
String objectName,
Expand All @@ -61,6 +64,7 @@ public B2EventNotificationEvent(String accountId,
this.bucketName = bucketName;
this.eventTimestamp = eventTimestamp;
this.eventType = eventType;
this.eventId = eventId;
this.eventVersion = eventVersion;
this.matchedRuleName = matchedRuleName;
this.objectName = objectName;
Expand All @@ -79,6 +83,7 @@ public boolean equals(Object o) {
Objects.equals(bucketId, that.bucketId) &&
Objects.equals(bucketName, that.bucketName) &&
Objects.equals(eventType, that.eventType) &&
Objects.equals(eventId, that.eventId) &&
Objects.equals(matchedRuleName, that.matchedRuleName) &&
Objects.equals(objectName, that.objectName) &&
Objects.equals(objectSize, that.objectSize) &&
Expand All @@ -93,6 +98,7 @@ public int hashCode() {
bucketName,
eventTimestamp,
eventType,
eventId,
eventVersion,
matchedRuleName,
objectName,
Expand Down Expand Up @@ -149,6 +155,13 @@ public String getEventType() {
return eventType;
}

/**
* The unique ID of the event.
*/
public String getEventId() {
return eventId;
}

/**
* The name of the object that corresponds to the event. This will be null for test events.
*/
Expand Down Expand Up @@ -178,6 +191,7 @@ public String toString() {
"accountId='" + accountId + '\'' +
", bucketId='" + bucketId + '\'' +
", bucketName='" + bucketName + '\'' +
", eventId=" + eventId + '\'' +
", eventTimestamp=" + eventTimestamp +
", eventType='" + eventType + '\'' +
", eventVersion=" + eventVersion +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void testToJsonAndBack() {
" \"accountId\": \"e85c6a500333\",\n" +
" \"bucketId\": \"aea8c5bc362ae55070130333\",\n" +
" \"bucketName\": \"mySampleBucket\",\n" +
" \"eventId\": \"eventId\",\n" +
" \"eventTimestamp\": 1684793309123,\n" +
" \"eventType\": \"b2:ObjectCreated:Upload\",\n" +
" \"eventVersion\": 1,\n" +
Expand All @@ -29,11 +30,19 @@ public void testToJsonAndBack() {
B2EventNotificationEvent.class
);

final B2EventNotificationEvent expectedEvent = new B2EventNotificationEvent("e85c6a500333", "aea8c5bc362ae55070130333", "mySampleBucket", 1684793309123L, "b2:ObjectCreated:Upload", 1,
final B2EventNotificationEvent expectedEvent = new B2EventNotificationEvent(
"e85c6a500333",
"aea8c5bc362ae55070130333",
"mySampleBucket",
1684793309123L,
"b2:ObjectCreated:Upload",
"eventId",
1,
"mySampleRule1",
"objectName.txt",
10495842L,
"4_zaea8c5bc362ae55070130333_f117c7bd5d6c6597c_d20230521_m235957_c001_v0001044_t0052_u01684713597235");
"4_zaea8c5bc362ae55070130333_f117c7bd5d6c6597c_d20230521_m235957_c001_v0001044_t0052_u01684713597235"
);
final String convertedJson = B2Json.toJsonOrThrowRuntime(expectedEvent);
assertEquals(expectedEvent, event);
assertEquals(jsonString, convertedJson);
Expand All @@ -45,6 +54,7 @@ public void testToJsonAndBack_testEvent() {
" \"accountId\": \"e85c6a500333\",\n" +
" \"bucketId\": \"aea8c5bc362ae55070130333\",\n" +
" \"bucketName\": \"mySampleBucket\",\n" +
" \"eventId\": \"eventId\",\n" +
" \"eventTimestamp\": 1684793309123,\n" +
" \"eventType\": \"b2:TestEvent\",\n" +
" \"eventVersion\": 1,\n" +
Expand All @@ -62,6 +72,7 @@ public void testToJsonAndBack_testEvent() {
"mySampleBucket",
1684793309123L,
"b2:TestEvent",
"eventId",
1,
"mySampleRule1",
null,
Expand All @@ -83,6 +94,7 @@ public void testTestEventsMustNotHaveObjectName() {
"mySampleBucket",
1684793309123L,
"b2:TestEvent",
"eventId",
1,
"mySampleRule1",
"objectName.txt",
Expand All @@ -103,6 +115,7 @@ public void testTestEventsMustNotHaveObjectSize() {
"mySampleBucket",
1684793309123L,
"b2:TestEvent",
"eventId",
1,
"mySampleRule1",
null,
Expand All @@ -123,6 +136,7 @@ public void testTestEventsMustNotHaveObjectVersionId() {
"mySampleBucket",
1684793309123L,
"b2:TestEvent",
"eventId",
1,
"mySampleRule1",
null,
Expand All @@ -143,6 +157,7 @@ public void testNonTestEventsMustHaveObjectName() {
"mySampleBucket",
1684793309123L,
"b2:ObjectCreated:Upload",
"eventId",
1,
"mySampleRule1",
null,
Expand All @@ -163,6 +178,7 @@ public void testNonTestEventsMustHaveObjectVersionId() {
"mySampleBucket",
1684793309123L,
"b2:ObjectCreated:Upload",
"eventId",
1,
"mySampleRule1",
"objectName.txt",
Expand All @@ -172,4 +188,4 @@ public void testNonTestEventsMustHaveObjectVersionId() {
);
assertEquals(illegalArgumentException.getMessage(), "objectVersionId is required");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class B2EventNotificationTest extends B2BaseTest {
" \"accountId\": \"e85c6a500333\",\n" +
" \"bucketId\": \"aea8c5bc362ae55070130333\",\n" +
" \"bucketName\": \"mySampleBucket\",\n" +
" \"eventId\": \"eventId\",\n" +
" \"eventTimestamp\": 1684793309123,\n" +
" \"eventType\": \"b2:ObjectCreated:Upload\",\n" +
" \"eventVersion\": 1,\n" +
Expand Down Expand Up @@ -54,6 +55,7 @@ public void testToJsonAndBack() {
"mySampleBucket",
1684793309123L,
"b2:ObjectCreated:Upload",
"eventId",
1,
"mySampleRule1",
"objectName.txt",
Expand All @@ -76,6 +78,7 @@ public void testToJsonAndBackWithNullSize() {
" \"accountId\": \"e85c6a500333\",\n" +
" \"bucketId\": \"aea8c5bc362ae55070130333\",\n" +
" \"bucketName\": \"mySampleBucket\",\n" +
" \"eventId\": \"eventId\",\n" +
" \"eventTimestamp\": 1684793309123,\n" +
" \"eventType\": \"b2:ObjectCreated:Upload\",\n" +
" \"eventVersion\": 1,\n" +
Expand All @@ -98,6 +101,7 @@ public void testToJsonAndBackWithNullSize() {
"mySampleBucket",
1684793309123L,
"b2:ObjectCreated:Upload",
"eventId",
1,
"mySampleRule1",
"objectName.txt",
Expand Down

0 comments on commit 7b7ee3d

Please sign in to comment.