Skip to content

Commit

Permalink
This PR removes the feature that SoilIndexedDictionary can be created…
Browse files Browse the repository at this point in the history
… without a transaction and used

- remove the code that checked for nil
- remove the code that transformed new values when a transaction is set
- Fix tests
- remove tests that where using the dict without a transaction

The newValues are now still there, but only used to create the transaction log and #hasIndexUpdates.
  • Loading branch information
MarcusDenker committed Dec 6, 2023
1 parent b4310b6 commit 14aea61
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 294 deletions.
12 changes: 9 additions & 3 deletions src/Soil-Core-Tests/SoilBackupTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ SoilBackupTest >> testBackupWithIndex [
dict := SoilSkipListDictionary new
keySize: 8;
maxLevel: 16.

tx := soil newTransaction.
tx root: dict.

dict at: #foo put: (SoilTestNestedObject new label: #indexed).
object := SoilTestClusterRoot new
nested: dict.
tx := soil newTransaction.
tx root: dict.
tx commit.
soil backupTo: self backupPath.
Expand All @@ -60,15 +63,18 @@ SoilBackupTest >> testBackupWithIndexRemoval [
| tx backup tx2 dict object |
"removed keys in indexes get objectId 0:0. On backup time we only
need to copy the non-removed"

dict := SoilSkipListDictionary new
keySize: 8;
maxLevel: 16.
tx := soil newTransaction.
tx root: dict.

dict at: #foo put: (SoilTestNestedObject new label: #indexed).
dict at: #bar put: (SoilTestNestedObject new label: #bar).
object := SoilTestClusterRoot new
nested: dict.
tx := soil newTransaction.
tx root: dict.

tx commit.
tx2 := soil newTransaction.
tx2 root removeKey: #bar.
Expand Down
184 changes: 13 additions & 171 deletions src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ SoilIndexedDictionaryTest >> testAddAndRemoveExistingList [

]

{ #category : #tests }
SoilIndexedDictionaryTest >> testAddAndRemoveOnNewList [
self
shouldnt: [ dict at: #foo put: #bar ]
raise: Error.
self assert: (dict at: #foo) equals: #bar.
dict removeKey: #foo.
self assert: dict size equals: 0
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testAddToExistingEmptyList [
| tx tx2 tx3 tx4 |
Expand Down Expand Up @@ -139,31 +129,6 @@ SoilIndexedDictionaryTest >> testAddToExistingNonEmptyList [
self assert: (tx4 root at: #foo) equals: #bar.
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testAddToNewList [
self
shouldnt: [ dict at: #foo put: #bar ]
raise: Error.
self assert: (dict at: #foo) equals: #bar
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testAt [
dict at: #foo2 put: #bar2.
dict at: #foo put: #bar.

self assert: (dict at: #foo2) equals: #bar2.
self should: [dict at: #ff] raise: KeyNotFound
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testAtIndex [
dict at: #foo2 put: #bar2.
dict at: #foo put: #bar.

self assert: (dict atIndex: 1) equals: #bar2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testAtIndexWithTransaction [
| tx tx2 |
Expand All @@ -183,9 +148,8 @@ SoilIndexedDictionaryTest >> testAtIndexWithTransaction [
SoilIndexedDictionaryTest >> testConcurrentAddKey [
| tx1 tx2 tx3 |
tx1 := soil newTransaction.
tx1 root: (dict
at: #one put: #onevalue;
yourself).
tx1 root: dict.
dict at: #one put: #onevalue.
tx1 commit.
tx2 := soil newTransaction.
"After creating tx2 we open a concurrent transaction and add a key to
Expand All @@ -202,12 +166,12 @@ SoilIndexedDictionaryTest >> testConcurrentAddKey [
SoilIndexedDictionaryTest >> testConcurrentDo [
| tx1 tx2 tx3 col |
tx1 := soil newTransaction.
tx1 root: (dict
tx1 root: dict.
dict
at: #one put: #onevalue;
at: #two put: #twovalue;
at: #three put: #threevalue;
at: #four put: #fourvalue;
yourself).
at: #four put: #fourvalue.
tx1 commit.
tx2 := soil newTransaction.
"After creating tx2 we open a concurrent transaction and add a key to
Expand All @@ -227,9 +191,10 @@ SoilIndexedDictionaryTest >> testConcurrentDo [
SoilIndexedDictionaryTest >> testConcurrentIsEmpty [
| tx1 tx2 tx3 |
tx1 := soil newTransaction.
tx1 root: (dict
at: #one put: #onevalue;
yourself).
tx1 root: dict.
dict
at: #one
put: #onevalue.
tx1 commit.
tx2 := soil newTransaction.
"After creating tx2 we open a concurrent transaction and add a key to
Expand All @@ -248,9 +213,10 @@ SoilIndexedDictionaryTest >> testConcurrentIsEmpty [
SoilIndexedDictionaryTest >> testConcurrentRemoveKey [
| tx1 tx2 tx3 |
tx1 := soil newTransaction.
tx1 root: (dict
at: #one put: #onevalue;
yourself).
tx1 root: dict.
dict
at: #one
put: #onevalue.
tx1 commit.
tx2 := soil newTransaction.
"After creating tx2 we open a concurrent transaction and remove a key to
Expand All @@ -264,19 +230,6 @@ SoilIndexedDictionaryTest >> testConcurrentRemoveKey [

]

{ #category : #tests }
SoilIndexedDictionaryTest >> testDo [
| counter |
dict at: #foo2 put: #bar2.
dict at: #foo put: #bar.

counter := 0.
dict do: [ :each |
self assert: (each beginsWith: 'bar').
counter := counter + 1].
self assert: counter equals: 2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testDoWithTransAction [
| tx tx1 tx2 counter |
Expand Down Expand Up @@ -315,33 +268,6 @@ SoilIndexedDictionaryTest >> testDoWithTransAction [

]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFirst [
dict at: #foo2 put: #bar2.
dict at: #foo put: #bar.

"first in key order"
self assert: dict first equals: #bar.
self assert: (dict first: 1) first equals: #bar.
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFirstAssociation [
dict at: #foo2 put: #bar2.
dict at: #foo put: #bar.

"firstAssocation in key order"
self assert: dict firstAssociation equals: #foo->#bar.
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFirstAssociationWithSingleRemovedItem [

dict at: #foo put: #bar.
dict removeKey: #foo.
self assert: dict firstAssociation equals: nil
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFirstAssociationWithTransaction [
| tx tx2 |
Expand All @@ -358,14 +284,6 @@ SoilIndexedDictionaryTest >> testFirstAssociationWithTransaction [

]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFirstWithSingleRemovedItem [

dict at: #foo put: #bar.
dict removeKey: #foo.
self assert: dict first equals: nil
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFirstWithTransaction [
| tx tx2 |
Expand Down Expand Up @@ -467,31 +385,6 @@ SoilIndexedDictionaryTest >> testIsEmpty [
self deny: tx1 root isEmpty.
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testLast [
dict at: #foo2 put: #bar2.
dict at: #foo put: #bar.

"last in key order"
self assert: dict last equals: #bar2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testLastAssociation [
dict at: #foo2 put: #bar2.
dict at: #foo put: #bar.

"last association in key order"
self assert: dict lastAssociation equals: #foo2->#bar2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testLastAssociationWithSingleRemovedItem [
dict at: #foo put: #bar.
dict removeKey: #foo.
self assert: dict lastAssociation equals: nil
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testLastAssociationWithTransaction [
| tx tx2 |
Expand All @@ -508,13 +401,6 @@ SoilIndexedDictionaryTest >> testLastAssociationWithTransaction [
self assert: tx2 root lastAssociation equals: 2->#two
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testLastWithSingleRemovedItem [
dict at: #foo put: #bar.
dict removeKey: #foo.
self assert: dict last equals: nil
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testLastWithTransaction [
| tx tx2 |
Expand Down Expand Up @@ -547,14 +433,6 @@ SoilIndexedDictionaryTest >> testLastWithTransactionRemoveLast [
self assert: tx2 root last equals: #one
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testNextAfter [
dict at: 1 put: #bar.
dict at: 2 put: #bar2.

self assert:( dict nextAfter: 1) equals: #bar2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testNextAfterWithTransaction [
| tx tx2 |
Expand All @@ -570,17 +448,6 @@ SoilIndexedDictionaryTest >> testNextAfterWithTransaction [
self assert: (tx2 root nextAfter: 1) value equals: #two
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testRemoveKey [
dict at: #foo put: #bar.
dict at: #foo2 put: #bar2.

dict removeKey: #foo.
self assert: dict size equals: 1.

self should: [ dict removeKey: #blah ] raise: KeyNotFound
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testRemoveKeyIfAbsentWithTransaction [

Expand Down Expand Up @@ -636,14 +503,6 @@ SoilIndexedDictionaryTest >> testRemoveKeyWithTwoTransactions [
self should: [tx commit] raise: SoilObjectHasConcurrentChange
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testSecond [
dict at: #foo put: #bar.
dict at: #foo2 put: #bar2.

self assert: dict second equals: #bar2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testSecondWithTransaction [
| tx tx2 |
Expand All @@ -659,14 +518,6 @@ SoilIndexedDictionaryTest >> testSecondWithTransaction [
self assert: tx2 root second equals: #two
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testSize [
dict at: #foo put: #bar.
dict at: #foo2 put: #bar2.

self assert: dict size equals: 2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testSizeWithTransaction [
| tx tx2 |
Expand All @@ -681,12 +532,3 @@ SoilIndexedDictionaryTest >> testSizeWithTransaction [
"and test last"
self assert: tx2 root size equals: 2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testValues [
dict at: #foo put: #bar.
dict at: #foo2 put: #bar2.

self assert: (dict values includes: 'bar').
self assert: (dict values includes: 'bar2')
]
Loading

0 comments on commit 14aea61

Please sign in to comment.