From fc843ee00ce69b4c6d990a884076b18664c79e36 Mon Sep 17 00:00:00 2001 From: Masashi Umezawa Date: Thu, 5 Sep 2024 23:30:08 +0900 Subject: [PATCH] Added testNextPutWithMessageId test case --- .../instance/testNextPut.st | 22 ---------- .../instance/testNextPutWithMessageId.st | 40 +++++++++++++++++++ .../RsStream.class/instance/beEmpty.st | 3 ++ .../instance/beEmptyAndReset.st | 4 ++ .../RsStream.class/instance/trimLowerThan..st | 3 ++ .../instance/initFromOrderedCollection..st | 1 + .../instance/initVariableAt.value..st | 4 +- .../instance/minId..st | 2 +- .../instance/minIdAtLeast..st | 2 +- 9 files changed, 55 insertions(+), 26 deletions(-) delete mode 100644 repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamTest.class/instance/testNextPut.st create mode 100644 repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamTest.class/instance/testNextPutWithMessageId.st create mode 100644 repository/RediStick-Stream-Objects.package/RsStream.class/instance/beEmpty.st create mode 100644 repository/RediStick-Stream-Objects.package/RsStream.class/instance/beEmptyAndReset.st create mode 100644 repository/RediStick-Stream-Objects.package/RsStream.class/instance/trimLowerThan..st diff --git a/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamTest.class/instance/testNextPut.st b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamTest.class/instance/testNextPut.st deleted file mode 100644 index f54b4c8..0000000 --- a/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamTest.class/instance/testNextPut.st +++ /dev/null @@ -1,22 +0,0 @@ -tests -testNextPut - | strm conts first second third | - strm := self newStreamNamed: 'testNextPut'. - strm trimTo: 0. - self assert: strm length equals: 0. - first := 'one' -> '1'. - second := 'two' -> '2'. - third := {'name' -> 'Foo'. 'mail' -> 'bar@baz.com'}. - strm nextPut: first. - strm nextPut: second. - strm nextPutAssociations: third. - self assert: strm length equals: 3. - conts := strm contents. - self assert: conts size equals: 3. - self assert: conts first content equals: first. - self assert: conts second content equals: second. - self assert: conts third contents equals: third. - strm trimTo: 0. - self assert: strm length equals: 0. - conts := strm contents. - self assert: conts size equals: 0. \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamTest.class/instance/testNextPutWithMessageId.st b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamTest.class/instance/testNextPutWithMessageId.st new file mode 100644 index 0000000..6f3ec4f --- /dev/null +++ b/repository/RediStick-Stream-Objects-Tests.package/RsRedisStreamTest.class/instance/testNextPutWithMessageId.st @@ -0,0 +1,40 @@ +tests +testNextPutWithMessageId + | strm one two three four five invalidId conts | + strm := self newStreamNamed: 'testNextPutWithMessageId'. + strm beEmptyAndReset. + self assert: strm length equals: 0. + one := 'one' -> '1'. + two := 'two' -> '2'. + three := 'three' -> '3'. + four := 'four' -> '4'. + five := 'five' -> '5'. + invalidId := RsStreamMessageId epoch. + self assert: (strm nextPut: one at: invalidId) equals: nil. + self assert: strm length equals: 0. + + strm nextPut: one at: '0-1'. + strm nextPut: two at: (RsStreamMessageId mainId: 0 subId: 2). + conts := strm contents. + self assert: strm length equals: 2. + self assert: conts first content equals: one. + self assert: conts second content equals: two. + + strm nextPut: three at: (RsStreamMessageId mainIdOnly: 1). + strm nextPut: four at: (RsStreamMessageId mainIdSubIncremented: 1). + self assert: (strm nextPut: five at: (RsStreamMessageId mainIdOnly: 1)) equals: nil. + conts := strm contents. + self assert: strm length equals: 4. + self assert: conts first content equals: one. + self assert: conts last content equals: four. + self assert: (conts collect: [ :each | each id ]) asArray equals: #('0-1' '0-2' '1-0' '1-1'). + self assert: strm info lastGeneratedId equals: '1-1'. + + strm trimLowerThan: (RsStreamMessageId mainId: 1 subId: 0). + conts := strm contents. + self assert: strm length equals: 2. + self assert: conts first content equals: three. + self assert: conts last content equals: four. + + strm trimTo: 0. + self assert: strm length equals: 0 \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects.package/RsStream.class/instance/beEmpty.st b/repository/RediStick-Stream-Objects.package/RsStream.class/instance/beEmpty.st new file mode 100644 index 0000000..f93ae3c --- /dev/null +++ b/repository/RediStick-Stream-Objects.package/RsStream.class/instance/beEmpty.st @@ -0,0 +1,3 @@ +deleting +beEmpty + self trimTo: 0 \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects.package/RsStream.class/instance/beEmptyAndReset.st b/repository/RediStick-Stream-Objects.package/RsStream.class/instance/beEmptyAndReset.st new file mode 100644 index 0000000..b7f6f98 --- /dev/null +++ b/repository/RediStick-Stream-Objects.package/RsStream.class/instance/beEmptyAndReset.st @@ -0,0 +1,4 @@ +deleting +beEmptyAndReset + self beEmpty. + self setLastMessageId: RsStreamMessageId epoch \ No newline at end of file diff --git a/repository/RediStick-Stream-Objects.package/RsStream.class/instance/trimLowerThan..st b/repository/RediStick-Stream-Objects.package/RsStream.class/instance/trimLowerThan..st new file mode 100644 index 0000000..5e06ae8 --- /dev/null +++ b/repository/RediStick-Stream-Objects.package/RsStream.class/instance/trimLowerThan..st @@ -0,0 +1,3 @@ +trimming +trimLowerThan: messageId + ^ self endpoint xTrim: self name minId: messageId \ No newline at end of file diff --git a/repository/RediStick-Stream.package/RsStreamInfo.class/instance/initFromOrderedCollection..st b/repository/RediStick-Stream.package/RsStreamInfo.class/instance/initFromOrderedCollection..st index 6f643ec..9e677bb 100644 --- a/repository/RediStick-Stream.package/RsStreamInfo.class/instance/initFromOrderedCollection..st +++ b/repository/RediStick-Stream.package/RsStreamInfo.class/instance/initFromOrderedCollection..st @@ -1,3 +1,4 @@ initialization initFromOrderedCollection: rawValues + rawValues ifNil: [ ^ self ]. rawValues pairsDo: [ :key :value | self initVariableAt: key value: value ] \ No newline at end of file diff --git a/repository/RediStick-Stream.package/RsStreamInfo.class/instance/initVariableAt.value..st b/repository/RediStick-Stream.package/RsStreamInfo.class/instance/initVariableAt.value..st index 820e541..8031336 100644 --- a/repository/RediStick-Stream.package/RsStreamInfo.class/instance/initVariableAt.value..st +++ b/repository/RediStick-Stream.package/RsStreamInfo.class/instance/initVariableAt.value..st @@ -8,7 +8,7 @@ initVariableAt: key value: value ^ self maxDeletedEntryId: value ]. key = 'entries-added' ifTrue: [ ^ self entriesAdded: value ]. key = 'groups' ifTrue: [ ^ self initGroups: value]. - key = 'first-entry' ifTrue: [ ^ self firstEntry: (RsStreamEntry fromOrderedCollection: value) ]. - key = 'last-entry' ifTrue: [ ^ self lastEntry: (RsStreamEntry fromOrderedCollection: value) ]. + (key = 'first-entry' and: [value notNil]) ifTrue: [ ^ self firstEntry: (RsStreamEntry fromOrderedCollection: value) ]. + (key = 'last-entry' and: [value notNil]) ifTrue: [ ^ self lastEntry: (RsStreamEntry fromOrderedCollection: value) ]. key = 'recorded-first-entry-id' ifTrue: [ ^ self recordedFirstEntryId: value ]. key = 'entries' ifTrue: [ ^ self initEntries: value ]. \ No newline at end of file diff --git a/repository/RediStick-Stream.package/RsStreamTrimOptions.class/instance/minId..st b/repository/RediStick-Stream.package/RsStreamTrimOptions.class/instance/minId..st index 0666d3f..fca465f 100644 --- a/repository/RediStick-Stream.package/RsStreamTrimOptions.class/instance/minId..st +++ b/repository/RediStick-Stream.package/RsStreamTrimOptions.class/instance/minId..st @@ -1,4 +1,4 @@ accessing minId: id self beMinId. - self threshold: id. \ No newline at end of file + self threshold: id asString. \ No newline at end of file diff --git a/repository/RediStick-Stream.package/RsStreamTrimOptions.class/instance/minIdAtLeast..st b/repository/RediStick-Stream.package/RsStreamTrimOptions.class/instance/minIdAtLeast..st index d654e61..abd6ef2 100644 --- a/repository/RediStick-Stream.package/RsStreamTrimOptions.class/instance/minIdAtLeast..st +++ b/repository/RediStick-Stream.package/RsStreamTrimOptions.class/instance/minIdAtLeast..st @@ -1,4 +1,4 @@ accessing minIdAtLeast: id self beMinId. - self atLeast: id \ No newline at end of file + self atLeast: id asString \ No newline at end of file