Skip to content

Commit

Permalink
Merge pull request #45 from zweidenker/hunting-self-exception
Browse files Browse the repository at this point in the history
Fixed wrong assignment of values
  • Loading branch information
noha authored Mar 22, 2020
2 parents fe475b2 + abe1d01 commit a7b59e4
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 90 deletions.
8 changes: 3 additions & 5 deletions source/SnapDump-Client/SDClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ SDClient >> projects [
{ #category : #searching }
SDClient >> snapshotWithId: aString project: aProjectString version: aVersionString [


^ (self store
^ self store
snapshotWithId: aString
project: aProjectString
version: aVersionString)
restoreModel;
yourself
version: aVersionString

]
50 changes: 29 additions & 21 deletions source/SnapDump-Core-Tests/SDCoreTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ SDCoreTests >> getDummySnapshotFromClient [
| snap |
snap := (client
snapshotWithId: self dummySnapshotId project: self projectNameForTests version: self versionStringForTests) .
snap project store: self store.
^ snap
]

{ #category : #tests }
SDCoreTests >> getDummySnapshotFromClient: aString [
| snap |
snap := (client
snapshotWithId: aString project: self projectNameForTests version: self versionStringForTests) .
^ snap
]

Expand Down Expand Up @@ -96,9 +103,9 @@ SDCoreTests >> testProjectVersions [
{ #category : #tests }
SDCoreTests >> testReadSnapshotFuelDump [

| snapshot context fuel |
self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient.
| snapshot context fuel s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
fuel := snapshot newReader fuelDumpStreamDo: [ :stream :length |
stream upToEnd ].

Expand All @@ -109,18 +116,18 @@ SDCoreTests >> testReadSnapshotFuelDump [
{ #category : #tests }
SDCoreTests >> testReadSnapshotMeta [

| snapshot |
self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient.
| snapshot s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
self assert: snapshot project name = 'TestProject'
]

{ #category : #tests }
SDCoreTests >> testReadSnapshotStackTrace [

| snapshot string stack |
self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient.
| snapshot string stack s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
self assert: snapshot project name = 'TestProject'.

stack := snapshot newReader stackTraceStreamDo: [ :stream :length |
Expand All @@ -147,9 +154,9 @@ SDCoreTests >> testRemoveProjectVersion [
{ #category : #tests }
SDCoreTests >> testRemoveSnapshot [

| snapshot |
self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient.
| snapshot s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
self assert: snapshot className equals: 'Object'.
self
shouldnt: [ snapshot remove ]
Expand All @@ -159,25 +166,26 @@ SDCoreTests >> testRemoveSnapshot [

{ #category : #tests }
SDCoreTests >> testRemoveVersion [
| snapshot |
self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient.
| snapshot s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
self assert: snapshot className equals: 'Object'.
snapshot version remove.
self assert: client projects isEmpty
]

{ #category : #tests }
SDCoreTests >> testSetup [
| mock root |
| mock root snapshot |
mock := self snapshotMock.
self
shouldnt: [ handler handleException: mock ]
raise: Error.
"only directories should be contained by the root path"
self deny: rootPath hasFiles.
self assert: rootPath hasDirectories.
root := self dummySnapshotRootPath.
snapshot := mock asSnapshot.
root := self dummySnapshotRootPath / snapshot exceptionId.
self assert: root exists.
self assert: root isDirectory.
self assert: ((root / mock asSnapshot snapshotId), #snap) exists.
Expand All @@ -187,9 +195,9 @@ SDCoreTests >> testSetup [
{ #category : #tests }
SDCoreTests >> testSnapshot [

| snapshot |
self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient.
| snapshot s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
self assert: snapshot className equals: 'Object'
]

Expand Down
8 changes: 4 additions & 4 deletions source/SnapDump-Core-Tests/SDTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ SDTests >> dummyContextSnapshot [

| snapshot |
snapshot := SDSnapshot dummyContextSnapshot.
snapshot exception instVarNamed: #id put: self dummyExceptionId.
"snapshot exception instVarNamed: #id put: self dummyExceptionId."
snapshot
instVarNamed: #exceptionId put: self dummyExceptionId;
instVarNamed: #snapshotId put: self dummySnapshotId;
"instVarNamed: #exceptionId put: self dummyExceptionId;"
"instVarNamed: #snapshotId put: self dummySnapshotId;"
yourself.
^ snapshot
]
Expand All @@ -40,7 +40,7 @@ SDTests >> dummySnapshotId [

{ #category : #tests }
SDTests >> dummySnapshotRootPath [
^ rootPath / self projectNameForTests / self versionStringForTests / self dummyExceptionId
^ rootPath / self projectNameForTests / self versionStringForTests

]

Expand Down
1 change: 0 additions & 1 deletion source/SnapDump-Core/SDException.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Class {
#name : #SDException,
#superclass : #Object,
#instVars : [
'string',
'version',
'id',
'exceptionClassName',
Expand Down
23 changes: 6 additions & 17 deletions source/SnapDump-Core/SDFilesystemStore.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ SDFilesystemStore class >> storeName [

{ #category : #services }
SDFilesystemStore >> buildExceptionFrom: aFileReference [
.
^ SDException new
id: aFileReference basename;
version: (self buildVersionFrom: aFileReference parent);
Expand All @@ -26,27 +25,14 @@ SDFilesystemStore >> buildExceptionFrom: aFileReference [

{ #category : #services }
SDFilesystemStore >> buildProjectFrom: aFileReference [
.
^ SDProject new
name: aFileReference basename;
store: self;
yourself
]

{ #category : #services }
SDFilesystemStore >> buildSnapshot: snapshotId exception: exceptionId project: projectName version: versionName [
.
^ SDFileSnapshot new
snapshotId: snapshotId;
projectName: projectName;
versionString: versionName;
exceptionId: exceptionId;
yourself
]

{ #category : #services }
SDFilesystemStore >> buildVersionFrom: aFileReference [
.
^ SDVersion new
string: aFileReference basename;
project: (self buildProjectFrom: aFileReference parent);
Expand Down Expand Up @@ -287,18 +273,21 @@ SDFilesystemStore >> snapshotPathForProject: aProjectName version: aVersionName

{ #category : #services }
SDFilesystemStore >> snapshotWithId: anIdString project: aProjectName version: aVersionString [
| file |
| file snapshot |
file := (self
snapshotFilesForProject: aProjectName
version: aVersionString)
detect:
[ :eachFile | eachFile basename = (self snapshotFileNameFor: anIdString) ]
ifNone: [ NotFound signal ].

^ (SDSnapshotFileReader file: file)
snapshot := (SDSnapshotFileReader file: file)
initializeFromMeta;
file: file;
snapshot
snapshot.
snapshot restoreModel.
snapshot project store: self.
^ snapshot
]

{ #category : #'service - getting' }
Expand Down
14 changes: 5 additions & 9 deletions source/SnapDump-Core/SDSnapshot.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ SDSnapshot class >> exception: anException [
^ self new exception: anException
]

{ #category : #accessing }
SDSnapshot class >> metaSeparator [
^ 255
]

{ #category : #accessing }
SDSnapshot class >> neoJsonMapping: mapper [
mapper for: self do: [ :mapping |
Expand Down Expand Up @@ -134,7 +129,9 @@ SDSnapshot >> errorSignature [
{ #category : #accessing }
SDSnapshot >> exception [

^ exception
^ exception ifNil: [
self restoreModel.
exception ]
]

{ #category : #accessing }
Expand All @@ -161,7 +158,6 @@ SDSnapshot >> exceptionId: aString [

{ #category : #initialization }
SDSnapshot >> exportExceptionModel [

"absorb the exception model properties so that they can be serialized with the snap file "
exceptionClass := self exception exceptionClassName.
selector := self exception exceptionSignalerSelector.
Expand Down Expand Up @@ -283,8 +279,8 @@ SDSnapshot >> restoreModel [
exception := SDException new
id: exceptionId;
exceptionSignalerSelector: selector;
exceptionSignalerClassName: exceptionClass;
exceptionClassName: className;
exceptionSignalerClassName: className;
exceptionClassName: exceptionClass;
yourself.
self ensureVersionModel

Expand Down
2 changes: 1 addition & 1 deletion source/SnapDump-Server-Tests/SDFileTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ SDFileTests >> testSimpleWrite [
snapshot := self createSimpleSnapshot.
self deny: rootPath hasFiles.
self assert: rootPath hasDirectories.
root := self dummySnapshotRootPath.
root := self dummySnapshotRootPath / snapshot exceptionId.
self assert: (root / snapshot snapshotId , #snap) exists
]
50 changes: 28 additions & 22 deletions source/SnapDump-Server-Tests/SDHTTPTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ SDHTTPTests >> dummySnapshotUrl [
^ (self apiVersionedUri /#projects / self projectNameForTests / #versions / self versionStringForTests / #exceptions / self dummyExceptionId / #snapshots / self dummySnapshotId)
]

{ #category : #tests }
SDHTTPTests >> dummySnapshotUrl: aSnapshot [
^ (self apiVersionedUri /#projects / self projectNameForTests / #versions / self versionStringForTests / #exceptions / self dummyExceptionId / #snapshots / aSnapshot snapshotId)
]

{ #category : #tests }
SDHTTPTests >> dummySnapshotUrlWithoutProject [
^ self apiVersionedUri
Expand Down Expand Up @@ -148,24 +153,25 @@ SDHTTPTests >> testProjectRemove [

{ #category : #tests }
SDHTTPTests >> testSetup [
| mock root |
| mock root snapshot |
mock := self snapshotMock.
self
shouldnt: [ handler handleException: mock ]
raise: Error.
snapshot := mock asSnapshot.
self assert: rootPath hasDirectories.
root := self dummySnapshotRootPath.
root := self dummySnapshotRootPath / snapshot exceptionId.
self assert: root hasFiles.
self assert: ((root / mock asSnapshot snapshotId), #snap) exists.

]

{ #category : #tests }
SDHTTPTests >> testSnapshotDelete [
| response |
self createSimpleSnapshot.
| response snapshot |
snapshot := self createSimpleSnapshot.
response := ZnClient new
url: self dummySnapshotUrl ;
url: (self dummySnapshotUrl: snapshot) ;
delete;
response.
self assert: response isSuccess.
Expand All @@ -185,15 +191,15 @@ SDHTTPTests >> testSnapshotEmptyVersion [

{ #category : #tests }
SDHTTPTests >> testSnapshotGet [
| response snapshot |
self createSimpleSnapshot.
| response snapshot s |
s := self createSimpleSnapshot.
response := ZnClient new
url: self dummySnapshotUrl ;
url: (self dummySnapshotUrl: s);
get;
response.
self assert: response isSuccess.
snapshot := (NeoJSONReader on: response contents readStream) nextAs: SDSnapshot .
self assert: snapshot snapshotId equals: self dummySnapshotId .
self assert: snapshot snapshotId equals: s snapshotId .

]

Expand All @@ -213,31 +219,31 @@ SDHTTPTests >> testSnapshotGetById [

{ #category : #tests }
SDHTTPTests >> testSnapshotGetContext [
| response snapshot context |
self createSimpleSnapshot.
| response snapshot context s |
s := self createSimpleSnapshot.
response := ZnClient new
url: self dummySnapshotUrl ;
url: (self dummySnapshotUrl: s) ;
get;
response.
self assert: response isSuccess.
snapshot := (NeoJSONReader on: response contents readStream) nextAs: SDSnapshot .
self assert: snapshot snapshotId equals: self dummySnapshotId.
self assert: snapshot snapshotId equals: s snapshotId.
context := FLMaterializer materializeFromByteArray: (self store snapshotDumpFor: snapshot).
self assert: (context isKindOf: Context).
self assert: context receiver = 'TestString'
]

{ #category : #tests }
SDHTTPTests >> testSnapshotGetStackTrace [
| response snapshot stackTrace |
self createSimpleSnapshot.
| response snapshot stackTrace s |
s := self createSimpleSnapshot.
response := ZnClient new
url: self dummySnapshotUrl ;
url: (self dummySnapshotUrl: s);
get;
response.
self assert: response isSuccess.
snapshot := (NeoJSONReader on: response contents readStream) nextAs: SDSnapshot .
self assert: snapshot snapshotId equals: self dummySnapshotId.
self assert: snapshot snapshotId equals: s snapshotId.
stackTrace := self store snapshotStackFor: snapshot.
self assert: (stackTrace includesSubstring: 'ByteString(Object)>>printStringLimitedTo:
Receiver: ''TestString'''
Expand All @@ -247,16 +253,16 @@ SDHTTPTests >> testSnapshotGetStackTrace [

{ #category : #tests }
SDHTTPTests >> testSnapshotList [
| response list |
self createSimpleSnapshot.
| response list s |
s := self createSimpleSnapshot.
response := ZnClient new
url: self apiVersionedUri / #projects / #TestProject / #versions / '0.1' / #exceptions / self dummyExceptionId / #snapshots;
url: self apiVersionedUri / #projects / #TestProject / #versions / '0.1' / #exceptions / s exceptionId / #snapshots;
get;
response.
self assert: response isSuccess equals: true.
self assert: response isSuccess.
list := (NeoJSONReader on: response contents readStream) nextListAs: SDSnapshot .
self assert: list size equals: 1.
self assert: (list first restoreModel; errorSignature) equals: 'TestProject_0.1_Object: ContextWithoutException>>#printStringLimitedTo:'
self assert: (list first restoreModel; errorSignature) equals: 'TestProject_0.1_ContextWithoutException: Object>>#printStringLimitedTo:'

]

Expand Down
Loading

0 comments on commit a7b59e4

Please sign in to comment.