'From Pharo1.0rc1 of 19 October 2009 [Latest update: #10493] on 8 December 2009 at 9:10:53 pm'!
TestCase subclass: #BMTTryingToUnderstandMagmaCommitConflictsTest
instanceVariableNames: 'magmaServerConsole'
classVariableNames: ''
poolDictionaries: ''
category: 'BkbagMagmaTesting-Model-Magma-IntegrationTests'!
Object subclass: #SomeMockDomainObject
instanceVariableNames: 'aField'
classVariableNames: ''
poolDictionaries: ''
category: 'BkbagMagmaTesting-Model-Magma-IntegrationTests'!
!BMTTryingToUnderstandMagmaCommitConflictsTest methodsFor: 'tests' stamp: 'TestRunner 12/8/2009 20:19'!
testTriggerACommitConflictLoadObjectBeforeStartingATransaction
|firstSession secondSession mockObjectRefByFirstSession mockObjectRefBySecondSession|
[firstSession :=
(MagmaRemoteLocation
host: 'localhost'
port: self databasePort) newSession.
firstSession connectAs: 'firstSessionUser'.
firstSession commit: [
firstSession root
at: 'mockObject'
put: (SomeMockDomainObject new aField: 'aField content'; yourself)].
secondSession :=
(MagmaRemoteLocation
host: 'localhost'
port: self databasePort) newSession.
secondSession connectAs: 'secondSessionUser'.
mockObjectRefByFirstSession := firstSession root at: 'mockObject'. "User 1 is loading the object"
mockObjectRefBySecondSession := secondSession root at: 'mockObject'. "User 2 is loading the same version of the object as User 1"
firstSession begin. "1. User 1 begins a transaction."
secondSession begin. "2. User 2 begins a transaction."
mockObjectRefByFirstSession aField: 'aField updated by user 1'. "3. User 1 changes Object A."
firstSession commit. "4. User 1 commits his transaction."
mockObjectRefBySecondSession aField: 'aField updated by user 2'. "5. User 2 changes Object A."
self should: [secondSession commit. "6.7. User 2 commits his transaction"]
raise: MagmaCommitConflictError.
self assert: 'aField updated by user 1' equals: ((firstSession root at: 'mockObject') aField).
self assert: 'aField updated by user 1' equals: ((secondSession root at: 'mockObject') aField).
self assert: 'aField updated by user 1' equals: (mockObjectRefBySecondSession aField).
] ensure: [[firstSession commit: [
firstSession root removeAll].
firstSession disconnect]
ensure:
[secondSession disconnect]]
! !
!BMTTryingToUnderstandMagmaCommitConflictsTest methodsFor: 'tests' stamp: 'TestRunner 12/8/2009 20:17'!
testTriggerACommitConflictSequenceAsDescribedOnWiki
|firstSession secondSession mockObjectRefByFirstSession mockObjectRefBySecondSession|
[firstSession :=
(MagmaRemoteLocation
host: 'localhost'
port: self databasePort) newSession.
firstSession connectAs: 'firstSessionUser'.
firstSession commit: [
firstSession root
at: 'mockObject'
put: (SomeMockDomainObject new aField: 'aField content'; yourself)].
secondSession :=
(MagmaRemoteLocation
host: 'localhost'
port: self databasePort) newSession.
secondSession connectAs: 'secondSessionUser'.
firstSession begin. "1. User 1 begins a transaction."
secondSession begin. "2. User 2 begins a transaction."
mockObjectRefByFirstSession := firstSession root at: 'mockObject'. "User 1 is loading the object"
mockObjectRefBySecondSession := secondSession root at: 'mockObject'. "User 2 is loading the same version of the object as User 1"
mockObjectRefByFirstSession aField: 'aField updated by user 1'. "3. User 1 changes Object A."
firstSession commit. "4. User 1 commits his transaction."
mockObjectRefBySecondSession aField: 'aField updated by user 2'. "5. User 2 changes Object A."
self should: [secondSession commit. "6.7. User 2 commits his transaction"]
raise: MagmaCommitConflictError.
self assert: 'aField updated by user 1' equals: ((firstSession root at: 'mockObject') aField).
self assert: 'aField updated by user 1' equals: ((secondSession root at: 'mockObject') aField).
self assert: 'aField updated by user 1' equals: (mockObjectRefBySecondSession aField).
] ensure: [[firstSession commit: [
firstSession root removeAll].
firstSession disconnect]
ensure:
[secondSession disconnect]]
! !
!BMTTryingToUnderstandMagmaCommitConflictsTest methodsFor: 'tests' stamp: 'TestRunner 12/8/2009 20:47'!
testTriggerACommitConflictUsersCommitAfterEachOtherButWithTheSameVersionOfObjectInitiallyLoaded
|firstSession secondSession mockObjectRefByFirstSession mockObjectRefBySecondSession|
[firstSession :=
(MagmaRemoteLocation
host: 'localhost'
port: self databasePort) newSession.
firstSession connectAs: 'firstSessionUser'.
firstSession commit: [
firstSession root
at: 'mockObject'
put: (SomeMockDomainObject new aField: 'aField content'; yourself)].
secondSession :=
(MagmaRemoteLocation
host: 'localhost'
port: self databasePort) newSession.
secondSession connectAs: 'secondSessionUser'.
mockObjectRefByFirstSession := firstSession root at: 'mockObject'. "User 1 is loading the object"
mockObjectRefBySecondSession := secondSession root at: 'mockObject'. "User 2 is loading the same version of the object as User 1"
firstSession begin. "1. User 1 begins a transaction."
mockObjectRefByFirstSession aField: 'aField updated by user 1'. "3. User 1 changes Object A."
firstSession commit. "4. User 1 commits his transaction."
secondSession begin. "2. User 2 begins a transaction."
mockObjectRefBySecondSession aField: 'aField updated by user 2'. "5. User 2 changes Object A."
self should: [secondSession commit. "6.7. User 2 commits his transaction"]
raise: MagmaCommitConflictError.
firstSession refresh.
self assert: 'aField updated by user 1' equals: ((firstSession root at: 'mockObject') aField).
self assert: 'aField updated by user 1' equals: ((secondSession root at: 'mockObject') aField).
self assert: 'aField updated by user 1' equals: (mockObjectRefBySecondSession aField).
] ensure: [[firstSession commit: [
firstSession root removeAll].
firstSession disconnect]
ensure:
[secondSession disconnect]]
! !
!BMTTryingToUnderstandMagmaCommitConflictsTest methodsFor: 'running' stamp: 'TestRunner 12/8/2009 19:49'!
setUp
super setUp.
self ensureRepositoryCreated.
magmaServerConsole :=
MagmaServerConsole new
open: self databasePath;
processOn: self databasePort;
yourself.
! !
!BMTTryingToUnderstandMagmaCommitConflictsTest methodsFor: 'running' stamp: 'TestRunner 12/8/2009 16:21'!
tearDown
super tearDown.
magmaServerConsole shutdown.! !
!BMTTryingToUnderstandMagmaCommitConflictsTest methodsFor: 'helper' stamp: 'TestRunner 12/8/2009 16:20'!
databasePath
^'tryingToUnderStandMagmaCommitConflicts'! !
!BMTTryingToUnderstandMagmaCommitConflictsTest methodsFor: 'helper' stamp: 'TestRunner 12/8/2009 16:26'!
databasePort
^55789
! !
!BMTTryingToUnderstandMagmaCommitConflictsTest methodsFor: 'helper' stamp: 'TestRunner 12/8/2009 16:21'!
ensureRepositoryCreated
((FileDirectory forFileName: '') directoryExists: self databasePath)
ifFalse:
[MagmaRepositoryController
create: self databasePath
root: Dictionary new]. ! !
!SomeMockDomainObject methodsFor: 'accessing' stamp: 'TestRunner 12/8/2009 16:24'!
aField
^ aField! !
!SomeMockDomainObject methodsFor: 'accessing' stamp: 'TestRunner 12/8/2009 16:24'!
aField: anObject
aField := anObject! !
BMTTryingToUnderstandMagmaCommitConflictsTest removeSelector: #testTriggerACommitConflict!
BMTTryingToUnderstandMagmaCommitConflictsTest removeSelector: #testTriggerACommitConflict2!
!BMTTryingToUnderstandMagmaCommitConflictsTest reorganize!
('tests' testTriggerACommitConflictLoadObjectBeforeStartingATransaction testTriggerACommitConflictSequenceAsDescribedOnWiki testTriggerACommitConflictUsersCommitAfterEachOtherButWithTheSameVersionOfObjectInitiallyLoaded)
('running' setUp tearDown)
('helper' databasePath databasePort ensureRepositoryCreated)
!