Skip to content

Commit

Permalink
Added tests for more GS queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mtabacman committed Jan 11, 2024
1 parent 7e0ce12 commit e1a8298
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GemStoneRepositoryProviderTest >> setUpRepositoryWith: aConflictCheckingStrategy
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testFindApplyingWhenCollectionIsLarge [
GemStoneRepositoryProviderTest >> testQueryingWhenCollectionIsLargeAndIndexed [

4 timesRepeat: [
1000 timesRepeat: [
Expand All @@ -43,15 +43,20 @@ GemStoneRepositoryProviderTest >> testFindApplyingWhenCollectionIsLarge [
].
self
should: [
self
assert: ( self extraterrestrials findApplying: 'each.firstName = ''Silvester''' ) size
equals: 4
self extraterrestrials withQueryFrom: 'each.firstName = ''Silvester''' do: [ :query |
self assert: query size equals: 4.
query do: [ :extraterrestrial |
self
assert: extraterrestrial firstName equals: 'Silvester';
assert: extraterrestrial lastName equals: 'Stallone'
]
]
]
notTakeMoreThanMilliseconds: 1
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testFindApplyingWhenCollectionIsLargeAndNotIndexed [
GemStoneRepositoryProviderTest >> testQueryingWhenCollectionIsLargeButNotIndexed [

| notIndexed |

Expand All @@ -76,9 +81,18 @@ GemStoneRepositoryProviderTest >> testFindApplyingWhenCollectionIsLargeAndNotInd
store: self ellaTravolta
]
].

self
should: [
self assert: ( notIndexed findApplying: 'each.firstName = ''Silvester''' ) size equals: 4 ]
notIndexed withQueryFrom: 'each.firstName = ''Silvester''' do: [ :query |
self assert: query size equals: 4.
query do: [ :extraterrestrial |
self
assert: extraterrestrial firstName equals: 'Silvester';
assert: extraterrestrial lastName equals: 'Stallone'
]
]
]
notTakeMoreThanMilliseconds: 17
]

Expand Down Expand Up @@ -151,6 +165,27 @@ GemStoneRepositoryProviderTest >> testSpaceshipWhenUsingIdentityIndex [
]
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testStreamQueryResults [

self extraterrestrials
store: self johnTravolta;
store: self johnLock;
store: self ellaTravolta;
store: self silvesterStallone.

self extraterrestrials withQueryFrom: 'each.firstName = ''Silvester''' do: [ :query |
| stream extraterrestrial |

stream := query readStream.
extraterrestrial := stream next.
self
assert: extraterrestrial firstName equals: 'Silvester';
assert: extraterrestrial lastName equals: 'Stallone'.
self assert: stream atEnd
]
]

{ #category : 'private - accessing' }
GemStoneRepositoryProviderTest >> timeLimitInMillisecondsWhenAdding [

Expand Down
16 changes: 8 additions & 8 deletions source/Sagan-GemStone/GemStoneRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ GemStoneRepository >> findAllMatching: aCriteriaOrBlock sortedBy: aSortFunction
^ ( self findAllMatching: aCriteriaOrBlock ) sorted: aSortFunction
]

{ #category : 'querying' }
GemStoneRepository >> findApplying: aQueryString [

^ ( GsQuery fromString: aQueryString )
on: contents;
queryResult
]

{ #category : 'configuring' }
GemStoneRepository >> indexByEquality: aPath typed: aType [

Expand Down Expand Up @@ -170,3 +162,11 @@ GemStoneRepository >> withOneMatching: aCriteriaOrBlock sortedBy: aSortFunction
ifFound: foundBlock
ifNone: noneBlock
]

{ #category : 'querying' }
GemStoneRepository >> withQueryFrom: aQueryString do: aBlock [

^ aBlock value: ( ( GsQuery fromString: aQueryString )
on: contents;
yourself )
]

0 comments on commit e1a8298

Please sign in to comment.