-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c844a7
commit a64f64d
Showing
14 changed files
with
704 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
src/Mapless-Redis-Observer-Tests/MaplessRedisObserverTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
Class { | ||
#name : #MaplessRedisObserverTest, | ||
#superclass : #MaplessTestCase, | ||
#instVars : [ | ||
'repository' | ||
], | ||
#category : #'Mapless-Redis-Observer-Tests' | ||
} | ||
|
||
{ #category : #'as yet unclassified' } | ||
MaplessRedisObserverTest class >> databaseIndex [ | ||
"Out of the box, a Redis instance supports 16 logical databases. These databases are effectively siloed off from one another, and when you run a command in one database it doesn’t affect any of the data stored in other databases in your Redis instance. | ||
Redis databases are numbered from 0 to 15 and, by default, you connect to database 0 when you connect to your Redis instance. However, you can change the database you’re using with the select command after you connect." | ||
|
||
^ 2 | ||
] | ||
|
||
{ #category : #actions } | ||
MaplessRedisObserverTest >> basicNewRepository [ | ||
^ MaplessRedisRepository | ||
for: self class databaseIndex | ||
with: MaplessRedisPool local | ||
using: MaplessTrivialResolver new | ||
] | ||
|
||
{ #category : #actions } | ||
MaplessRedisObserverTest >> newRepository [ | ||
| accessor | | ||
accessor := MaplessRedisPool local. | ||
accessor start. | ||
^ MaplessRedisRepository | ||
for: self class databaseIndex | ||
with: accessor | ||
using: MaplessTrivialResolver new | ||
] | ||
|
||
{ #category : #initialization } | ||
MaplessRedisObserverTest >> setUp [ | ||
super setUp. | ||
|
||
|
||
] | ||
|
||
{ #category : #initialization } | ||
MaplessRedisObserverTest >> tearDown [ | ||
super tearDown. | ||
repository | ||
ifNotNil: [ repository drop. | ||
repository accessor stop ] | ||
] | ||
|
||
{ #category : #tests } | ||
MaplessRedisObserverTest >> testCanSubscribeToSavedMapless [ | ||
|
||
| task valued reaction | | ||
repository := self newRepository. | ||
task := SampleTask new. | ||
valued := false. | ||
reaction := [ valued := true ]. | ||
repository save: task. | ||
self | ||
shouldnt: [ task pubsubWhen: #something send: #value to: reaction ] | ||
raise: MaplessObserverOnUnsaved | ||
] | ||
|
||
{ #category : #tests } | ||
MaplessRedisObserverTest >> testCannotSubscribeToUnsavedMapless [ | ||
|
||
| task valued reaction | | ||
repository := self newRepository. | ||
task := SampleTask new. | ||
valued := false. | ||
reaction := [ valued := true ]. | ||
self | ||
should: [ task pubsubWhen: #something send: #value to: reaction ] | ||
raise: MaplessObserverOnUnsaved | ||
] | ||
|
||
{ #category : #tests } | ||
MaplessRedisObserverTest >> testReactsToObservedPubsubEventWithLocalArguments [ | ||
|
||
| task1 task2 valued reaction receivedOne receivedTwo | | ||
MaplessRedisHelper repository: self newRepository. | ||
repository := MaplessRedisHelper repository. | ||
task1 := SampleTask new. | ||
valued := false. | ||
reaction := [ :first :second | | ||
valued := true. | ||
receivedOne := first. | ||
receivedTwo := second ]. | ||
repository save: task1. | ||
self deny: valued. | ||
task1 | ||
pubsubWhen: #doTheThing | ||
send: #value:value: | ||
to: reaction | ||
withArguments: { $a. 42 }. | ||
self deny: valued. | ||
task2 := repository findOne: SampleTask atId: task1 id. | ||
|
||
task2 pubsubTriggerEvent: #doTheThing. | ||
5 milliSeconds asDelay wait. | ||
self assert: valued. | ||
self assert: receivedOne equals: $a. | ||
self assert: receivedTwo equals: 42 | ||
] | ||
|
||
{ #category : #tests } | ||
MaplessRedisObserverTest >> testReactsToObservedPubsubEventWithOneLocalArgument [ | ||
|
||
| task1 task2 valued reaction receivedArguments | | ||
MaplessRedisHelper repository: self newRepository. | ||
repository := MaplessRedisHelper repository. | ||
task1 := SampleTask new. | ||
valued := false. | ||
reaction := [ :args | | ||
valued := true. | ||
receivedArguments := args ]. | ||
repository save: task1. | ||
self deny: valued. | ||
task1 | ||
pubsubWhen: #doTheThing | ||
send: #value: | ||
to: reaction | ||
with: 42. | ||
self deny: valued. | ||
self assert: receivedArguments isNil. | ||
task2 := repository findOne: SampleTask atId: task1 id. | ||
Transcript crShow: valued. | ||
task2 pubsubTriggerEvent: #doTheThing. | ||
5 milliSeconds asDelay wait. | ||
self assert: valued. | ||
self assert: receivedArguments notNil. | ||
self assert: receivedArguments equals: 42 | ||
] | ||
|
||
{ #category : #tests } | ||
MaplessRedisObserverTest >> testReactsToObservedPubsubEventWithoutArguments [ | ||
|
||
| task1 task2 valued reaction | | ||
MaplessRedisHelper repository: self newRepository. | ||
repository := MaplessRedisHelper repository. | ||
task1 := SampleTask new. | ||
valued := false. | ||
reaction := [ valued := true ]. | ||
repository save: task1. | ||
self deny: valued. | ||
task1 pubsubWhen: #doTheThing send: #value to: reaction. | ||
self deny: valued. | ||
task2 := repository findOne: SampleTask atId: task1 id. | ||
|
||
task2 pubsubTriggerEvent: #doTheThing. | ||
5 milliSeconds asDelay wait. | ||
self assert: valued | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Mapless-Redis-Observer-Tests' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Extension { #name : #Mapless } | ||
|
||
{ #category : #'*Mapless-Redis-Observer' } | ||
Mapless >> pubsubTriggerEvent: anEventSelector [ | ||
|
||
self class getPubsubRepository publish: anEventSelector from: self | ||
] | ||
|
||
{ #category : #'*Mapless-Redis-Observer' } | ||
Mapless >> pubsubTriggerEvent: anEventSelector with: anObject [ | ||
|
||
self flag: 'review remote arguments'. | ||
|
||
^ self | ||
pubsubTriggerEvent: anEventSelector | ||
withArguments: { anObject } | ||
] | ||
|
||
{ #category : #'*Mapless-Redis-Observer' } | ||
Mapless >> pubsubTriggerEvent: anEventSelector withArguments: anArgumentList [ | ||
|
||
self flag: 'review remote arguments'. | ||
self class getPubsubRepository | ||
publish: anEventSelector | ||
from: self | ||
arguments: (STON toString: anArgumentList) | ||
] | ||
|
||
{ #category : #'*Mapless-Redis-Observer' } | ||
Mapless >> pubsubUnsubscribe: anEventSelector [ | ||
|
||
self class getPubsubRepository | ||
unsubscribe: self | ||
from: anEventSelector | ||
] | ||
|
||
{ #category : #'*Mapless-Redis-Observer' } | ||
Mapless >> pubsubWhen: anEventSelector evaluate: anAction [ | ||
|
||
self class getPubsubRepository | ||
subscribe: self | ||
when: anEventSelector | ||
evaluate: anAction | ||
] | ||
|
||
{ #category : #'*Mapless-Redis-Observer' } | ||
Mapless >> pubsubWhen: anEventSelector send: aMessageSelector to: anObject [ | ||
|
||
self | ||
pubsubWhen: anEventSelector | ||
evaluate: | ||
(WeakMessageSend receiver: anObject selector: aMessageSelector) | ||
] | ||
|
||
{ #category : #'*Mapless-Redis-Observer' } | ||
Mapless >> pubsubWhen: anEventSelector send: aMessageSelector to: anObject with: anArg [ | ||
|
||
self pubsubWhen: anEventSelector evaluate: (WeakMessageSend | ||
receiver: anObject | ||
selector: aMessageSelector | ||
argument: anArg) | ||
] | ||
|
||
{ #category : #'*Mapless-Redis-Observer' } | ||
Mapless >> pubsubWhen: anEventSelector send: aMessageSelector to: anObject withArguments: anArgArray [ | ||
|
||
self pubsubWhen: anEventSelector evaluate: (WeakMessageSend | ||
receiver: anObject | ||
selector: aMessageSelector | ||
arguments: anArgArray) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Mapless-Redis-Observer' } |
Oops, something went wrong.