Skip to content

Commit

Permalink
reorganized packages
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianconcept committed Feb 4, 2024
1 parent 0c844a7 commit a64f64d
Show file tree
Hide file tree
Showing 14 changed files with 704 additions and 130 deletions.
16 changes: 13 additions & 3 deletions src/BaselineOfMapless/BaselineOfMapless.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,22 @@ BaselineOfMapless >> setUpRedisDependencies: spec [

{ #category : #baseline }
BaselineOfMapless >> setUpRedisPackages: spec [

spec
package: 'Mapless-Redis'
with: [ spec requires: #( 'Mapless-Base-Core' 'RediStick' ) ].

spec
package: 'Mapless-Redis-Core'
with: [ spec requires: #('Mapless-Base-Core' 'RediStick') ].
package: 'Mapless-Redis-Observer'
with: [ spec requires: #( 'Mapless-Base-Core' ) ].

spec package: 'Mapless-Redis-Observer-Tests' with: [
spec requires: #( 'Mapless-Redis-Observer' 'Mapless-Redis-Tests'
'Mapless-Tests-Base' ) ].

spec
package: 'Mapless-Redis-Tests'
with: [ spec requires: #('Mapless-Redis-Core' 'Mapless-Tests-Base') ]
with: [ spec requires: #( 'Mapless-Redis' 'Mapless-Tests-Base' ) ].
]

{ #category : #baseline }
Expand Down
156 changes: 156 additions & 0 deletions src/Mapless-Redis-Observer-Tests/MaplessRedisObserverTest.class.st
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
]
1 change: 1 addition & 0 deletions src/Mapless-Redis-Observer-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'Mapless-Redis-Observer-Tests' }
71 changes: 71 additions & 0 deletions src/Mapless-Redis-Observer/Mapless.extension.st
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)
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
#classInstVars : [
'repository'
],
#category : #'Mapless-Redis-Tests'
#category : #'Mapless-Redis-Observer'
}

{ #category : #initialization }
Expand Down
1 change: 1 addition & 0 deletions src/Mapless-Redis-Observer/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'Mapless-Redis-Observer' }
Loading

0 comments on commit a64f64d

Please sign in to comment.