Skip to content

Commit

Permalink
Merge pull request #540 from ApptiveGrid/revert-535-IndexedDict-force…
Browse files Browse the repository at this point in the history
…Transation
  • Loading branch information
noha authored Dec 7, 2023
2 parents c9c3211 + 440a9ce commit d7995e3
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 77 deletions.
12 changes: 3 additions & 9 deletions src/Soil-Core-Tests/SoilBackupTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ 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 @@ -63,18 +60,15 @@ 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: 171 additions & 13 deletions src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ 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 @@ -129,6 +139,31 @@ 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 @@ -148,8 +183,9 @@ SoilIndexedDictionaryTest >> testAtIndexWithTransaction [
SoilIndexedDictionaryTest >> testConcurrentAddKey [
| tx1 tx2 tx3 |
tx1 := soil newTransaction.
tx1 root: dict.
dict at: #one put: #onevalue.
tx1 root: (dict
at: #one put: #onevalue;
yourself).
tx1 commit.
tx2 := soil newTransaction.
"After creating tx2 we open a concurrent transaction and add a key to
Expand All @@ -166,12 +202,12 @@ SoilIndexedDictionaryTest >> testConcurrentAddKey [
SoilIndexedDictionaryTest >> testConcurrentDo [
| tx1 tx2 tx3 col |
tx1 := soil newTransaction.
tx1 root: dict.
dict
tx1 root: (dict
at: #one put: #onevalue;
at: #two put: #twovalue;
at: #three put: #threevalue;
at: #four put: #fourvalue.
at: #four put: #fourvalue;
yourself).
tx1 commit.
tx2 := soil newTransaction.
"After creating tx2 we open a concurrent transaction and add a key to
Expand All @@ -191,10 +227,9 @@ SoilIndexedDictionaryTest >> testConcurrentDo [
SoilIndexedDictionaryTest >> testConcurrentIsEmpty [
| tx1 tx2 tx3 |
tx1 := soil newTransaction.
tx1 root: dict.
dict
at: #one
put: #onevalue.
tx1 root: (dict
at: #one put: #onevalue;
yourself).
tx1 commit.
tx2 := soil newTransaction.
"After creating tx2 we open a concurrent transaction and add a key to
Expand All @@ -213,10 +248,9 @@ SoilIndexedDictionaryTest >> testConcurrentIsEmpty [
SoilIndexedDictionaryTest >> testConcurrentRemoveKey [
| tx1 tx2 tx3 |
tx1 := soil newTransaction.
tx1 root: dict.
dict
at: #one
put: #onevalue.
tx1 root: (dict
at: #one put: #onevalue;
yourself).
tx1 commit.
tx2 := soil newTransaction.
"After creating tx2 we open a concurrent transaction and remove a key to
Expand All @@ -230,6 +264,19 @@ 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 @@ -268,6 +315,33 @@ 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 @@ -284,6 +358,14 @@ 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 @@ -385,6 +467,31 @@ 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 @@ -401,6 +508,13 @@ 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 @@ -433,6 +547,14 @@ 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 @@ -448,6 +570,17 @@ 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 @@ -503,6 +636,14 @@ 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 @@ -518,6 +659,14 @@ 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 @@ -532,3 +681,12 @@ 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 d7995e3

Please sign in to comment.