-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-candidate' into localization
- Loading branch information
Showing
5 changed files
with
345 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
RwLoadSpecificationV2 { | ||
#specName: 'Bell', | ||
#projectName : 'Bell', | ||
#gitUrl : 'https://github.com/ba-st/Bell.git', | ||
#revision : 'v2', | ||
#projectSpecFile : 'rowan/project.ston', | ||
#componentNames : [ | ||
'Deployment', | ||
'Dependent-SUnit-Extensions' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
source/Hyperspace-Model-Tests/ZnEventToLogRecordAdapterTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
Class { | ||
#name : 'ZnEventToLogRecordAdapterTest', | ||
#superclass : 'TestCase', | ||
#instVars : [ | ||
'loggingAsserter', | ||
'zincEventToLogRecordAdapter' | ||
], | ||
#category : 'Hyperspace-Model-Tests-Zinc', | ||
#package : 'Hyperspace-Model-Tests', | ||
#tag : 'Zinc' | ||
} | ||
|
||
{ #category : 'private' } | ||
ZnEventToLogRecordAdapterTest >> addTimestampRegexTo: aLogEntryCollection [ | ||
|
||
^ aLogEntryCollection collect: [ :regexExpression | | ||
'\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d+)?(\+|-)(\d+\:\d+) <1s>' expandMacrosWith: | ||
regexExpression | ||
] | ||
] | ||
|
||
{ #category : 'private' } | ||
ZnEventToLogRecordAdapterTest >> runMemoryLoggerDuring: aBlock assertingLogRecordsMatchRegexes: expectedLogEntries [ | ||
|
||
| expectedLogEntriesWithTimestamp | | ||
|
||
expectedLogEntriesWithTimestamp := self addTimestampRegexTo: expectedLogEntries. | ||
|
||
loggingAsserter | ||
runMemoryLoggerDuring: aBlock; | ||
assertLogRecordsMatchUsing: expectedLogEntriesWithTimestamp | ||
] | ||
|
||
{ #category : 'running' } | ||
ZnEventToLogRecordAdapterTest >> setUp [ | ||
|
||
super setUp. | ||
loggingAsserter := LoggingAsserter on: self. | ||
zincEventToLogRecordAdapter := ZnEventToLogRecordAdapter new | ||
] | ||
|
||
{ #category : 'running' } | ||
ZnEventToLogRecordAdapterTest >> tearDown [ | ||
|
||
zincEventToLogRecordAdapter stopListeners. | ||
loggingAsserter stopLoggers. | ||
|
||
super tearDown | ||
] | ||
|
||
{ #category : 'running' } | ||
ZnEventToLogRecordAdapterTest >> testLogsOfIncomingGetRequest [ | ||
|
||
zincEventToLogRecordAdapter | ||
logIncomingRequests: true; | ||
startUpListeners. | ||
|
||
self | ||
runMemoryLoggerDuring: [ | ||
self withServerDo: [ :server | | ||
| client | | ||
server onRequestRespond: [ :request | | ||
( ZnResponse ok: ( ZnEntity textCRLF: 'OK' ) ) | ||
setConnectionClose; | ||
yourself | ||
]. | ||
client := ZnClient new. | ||
client url: server localUrl. | ||
client get | ||
] | ||
] | ||
assertingLogRecordsMatchRegexes: | ||
#( '\[DEBUG\] Server accepted connection \{"remoteAddress"\:"127.0.0.1","processId"\:(\d+),"eventId"\:(\d+)\}' | ||
'\[DEBUG\] Incoming HTTP request received \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Read a\s{0,1}ZnRequest\(GET /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"GET","uri"\:"/"\},"processId"\:(\d+),"eventId"\:(\d+)\}' | ||
'\[DEBUG\] Incoming HTTP request responded \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Handled a\s{0,1}ZnRequest\(GET /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"GET","uri"\:"/"\},"processId"\:(\d+),"eventId"\:(\d+),"response"\:\{"code"\:200,"totalSize"\:(\d+)\}\}' | ||
'\[DEBUG\] Server closed connection \{"remoteAddress"\:"127.0.0.1","processId"\:(\d+),"eventId"\:(\d+)\}' ) | ||
] | ||
{ #category : 'running' } | ||
ZnEventToLogRecordAdapterTest >> testLogsOfIncomingPostRequest [ | ||
zincEventToLogRecordAdapter | ||
logIncomingRequests: true; | ||
startUpListeners. | ||
self | ||
runMemoryLoggerDuring: [ | ||
self withServerDo: [ :server | | ||
| client | | ||
server onRequestRespond: [ :request | | ||
( ZnResponse ok: ( ZnEntity textCRLF: 'Hi you too!' ) ) | ||
setConnectionClose; | ||
yourself | ||
]. | ||
client := ZnClient new. | ||
client post: server localUrl contents: 'Hi there!' | ||
] | ||
] | ||
assertingLogRecordsMatchRegexes: | ||
#( '\[DEBUG\] Server accepted connection \{"remoteAddress"\:"127.0.0.1","processId"\:(\d+),"eventId"\:(\d+)\}' | ||
'\[DEBUG\] Incoming HTTP request received \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Read a\s{0,1}ZnRequest\(POST /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"POST","uri"\:"/"\},"processId"\:(\d+),"eventId"\:(\d+)\}' | ||
'\[DEBUG\] Incoming HTTP request responded \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Handled a\s{0,1}ZnRequest\(POST /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"POST","uri"\:"/"\},"processId"\:(\d+),"eventId"\:(\d+),"response"\:\{"code"\:200,"totalSize"\:(\d+)\}\}' | ||
'\[DEBUG\] Server closed connection \{"remoteAddress"\:"127.0.0.1","processId"\:(\d+),"eventId"\:(\d+)\}' ) | ||
] | ||
{ #category : 'running' } | ||
ZnEventToLogRecordAdapterTest >> testLogsOfOutgoingGetRequest [ | ||
zincEventToLogRecordAdapter | ||
logOutgoingRequests: true; | ||
startUpListeners. | ||
self | ||
runMemoryLoggerDuring: [ | ||
self withServerDo: [ :server | | ||
| client | | ||
server onRequestRespond: [ :request | | ||
( ZnResponse ok: ( ZnEntity textCRLF: 'OK' ) ) | ||
setConnectionClose; | ||
yourself | ||
]. | ||
client := ZnClient new. | ||
client url: server localUrl. | ||
client get | ||
] | ||
] | ||
assertingLogRecordsMatchRegexes: | ||
#( '\[DEBUG\] Outgoing HTTP request sent \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Written a\s{0,1}ZnRequest\(GET /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"GET","uri"\:"http\://localhost\:(\d+)/"\},"processId"\:(\d+),"eventId"\:(\d+)\}' | ||
'\[DEBUG\] Outgoing HTTP request responded \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? GET / 200 (\d+)B (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"GET","uri"\:"http\://localhost\:(\d+)/"\},"processId"\:(\d+),"eventId"\:(\d+),"response"\:\{"code"\:200,"totalSize"\:(\d+)\}\}' ) | ||
] | ||
{ #category : 'running' } | ||
ZnEventToLogRecordAdapterTest >> testLogsOfOutgoingPostRequest [ | ||
zincEventToLogRecordAdapter | ||
logOutgoingRequests: true; | ||
startUpListeners. | ||
self | ||
runMemoryLoggerDuring: [ | ||
self withServerDo: [ :server | | ||
| client | | ||
server onRequestRespond: [ :request | | ||
( ZnResponse ok: ( ZnEntity textCRLF: 'Hi you too!' ) ) | ||
setConnectionClose; | ||
yourself | ||
]. | ||
client := ZnClient new. | ||
client post: server localUrl contents: 'Hi there!' | ||
] | ||
] | ||
assertingLogRecordsMatchRegexes: | ||
#( '\[DEBUG\] Outgoing HTTP request sent \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Written a\s{0,1}ZnRequest\(POST /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"POST","uri"\:"http\://localhost\:(\d+)/"\},"processId"\:(\d+),"eventId"\:(\d+)\}' | ||
'\[DEBUG\] Outgoing HTTP request responded \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? POST / 200 (\d+)B (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"POST","uri"\:"http\://localhost\:(\d+)/"\},"processId"\:(\d+),"eventId"\:(\d+),"response"\:\{"code"\:200,"totalSize"\:(\d+)\}\}' ) | ||
] | ||
{ #category : 'enumerating' } | ||
ZnEventToLogRecordAdapterTest >> withServerDo: block [ | ||
ZnServer withOSAssignedPortDo: block | ||
] |
153 changes: 153 additions & 0 deletions
153
source/Hyperspace-Model/ZnEventToLogRecordAdapter.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
Class { | ||
#name : 'ZnEventToLogRecordAdapter', | ||
#superclass : 'Object', | ||
#instVars : [ | ||
'logOutgoingRequests', | ||
'logIncomingRequests', | ||
'subscriptions' | ||
], | ||
#category : 'Hyperspace-Model', | ||
#package : 'Hyperspace-Model' | ||
} | ||
|
||
{ #category : 'private - dumping' } | ||
ZnEventToLogRecordAdapter >> asStructuredRequest: aZnRequest [ | ||
|
||
| json | | ||
|
||
json := NeoJSONObject new. | ||
json | ||
at: #method put: aZnRequest method; | ||
at: #uri put: aZnRequest uri asString. | ||
^json | ||
] | ||
|
||
{ #category : 'private - dumping' } | ||
ZnEventToLogRecordAdapter >> asStructuredResponse: aZnResponse [ | ||
|
||
| json | | ||
|
||
json := NeoJSONObject new. | ||
json | ||
at: #code put: aZnResponse code; | ||
at: #totalSize put: aZnResponse contentLength. | ||
^json | ||
] | ||
|
||
{ #category : 'private - dumping' } | ||
ZnEventToLogRecordAdapter >> dumpConnectionEvent: aZnServerConnectionClosedEvent on: data [ | ||
|
||
data | ||
at: #remoteAddress put: ( self ipAddressToString: aZnServerConnectionClosedEvent ); | ||
at: #processId put: aZnServerConnectionClosedEvent processId; | ||
at: #eventId put: aZnServerConnectionClosedEvent id | ||
] | ||
|
||
{ #category : 'private - dumping' } | ||
ZnEventToLogRecordAdapter >> dumpRequestAndResponseOf: event on: json [ | ||
|
||
| response | | ||
|
||
self dumpRequestOf: event on: json. | ||
response := event response. | ||
(response hasEntity | ||
and: [response entity hasContentType and: [response entity contentType isBinary not]]) | ||
then: [json at: #response put: (self asStructuredResponse: response)]. | ||
^json | ||
] | ||
|
||
{ #category : 'private - dumping' } | ||
ZnEventToLogRecordAdapter >> dumpRequestOf: event on: json [ | ||
|
||
json | ||
at: #summary put: event printString; | ||
at: #durationInMilliseconds put: event duration; | ||
at: #request put: (self asStructuredRequest: event request); | ||
at: #processId put: event processId; | ||
at: #eventId put: event id. | ||
^json | ||
] | ||
|
||
{ #category : 'system startup' } | ||
ZnEventToLogRecordAdapter >> initialize [ | ||
|
||
super initialize. | ||
|
||
logOutgoingRequests := false. | ||
logIncomingRequests := false. | ||
subscriptions := OrderedCollection new | ||
] | ||
|
||
{ #category : 'private - dumping' } | ||
ZnEventToLogRecordAdapter >> ipAddressToString: aZnServerConnectionClosedEvent [ | ||
|
||
^ aZnServerConnectionClosedEvent address isString | ||
then: [ aZnServerConnectionClosedEvent address ] | ||
otherwise: [ ZnNetworkingUtils ipAddressToString: aZnServerConnectionClosedEvent address ] | ||
] | ||
|
||
{ #category : 'private - configuring' } | ||
ZnEventToLogRecordAdapter >> logIncomingRequests: aBoolean [ | ||
|
||
logIncomingRequests := aBoolean | ||
] | ||
|
||
{ #category : 'private - configuring' } | ||
ZnEventToLogRecordAdapter >> logOutgoingRequests: aBoolean [ | ||
|
||
logOutgoingRequests := aBoolean | ||
] | ||
|
||
{ #category : 'system startup' } | ||
ZnEventToLogRecordAdapter >> startUpIncomingRequestListeners [ | ||
|
||
self subscribeToEventsOf: ZnServerConnectionClosedEvent andDo: [ :event | | ||
LogRecord emitStructuredDebuggingInfo: 'Server closed connection' | ||
with: [ :data | self dumpConnectionEvent: event on: data ] | ||
]. | ||
self subscribeToEventsOf: ZnConnectionAcceptedEvent andDo: [ :event | | ||
LogRecord emitStructuredDebuggingInfo: 'Server accepted connection' | ||
with: [ :data | self dumpConnectionEvent: event on: data ] | ||
]. | ||
self subscribeToEventsOf: ZnRequestReadEvent andDo: [ :event | | ||
LogRecord emitStructuredDebuggingInfo: 'Incoming HTTP request received' | ||
with: [ :data | self dumpRequestOf: event on: data ] | ||
]. | ||
self subscribeToEventsOf: ZnRequestResponseHandledEvent andDo: [ :event | | ||
LogRecord emitStructuredDebuggingInfo: 'Incoming HTTP request responded' | ||
with: [ :data | self dumpRequestAndResponseOf: event on: data ] | ||
] | ||
] | ||
|
||
{ #category : 'system startup' } | ||
ZnEventToLogRecordAdapter >> startUpListeners [ | ||
|
||
logOutgoingRequests then: [ self startUpOutgoingRequestListeners ]. | ||
|
||
logIncomingRequests then: [ self startUpIncomingRequestListeners ] | ||
] | ||
|
||
{ #category : 'system startup' } | ||
ZnEventToLogRecordAdapter >> startUpOutgoingRequestListeners [ | ||
|
||
self subscribeToEventsOf: ZnRequestWrittenEvent andDo: [ :event | | ||
LogRecord emitStructuredDebuggingInfo: 'Outgoing HTTP request sent' | ||
with: [ :data | self dumpRequestOf: event on: data ] | ||
]. | ||
self subscribeToEventsOf: ZnClientTransactionEvent andDo: [ :event | | ||
LogRecord emitStructuredDebuggingInfo: 'Outgoing HTTP request responded' | ||
with: [ :data | self dumpRequestAndResponseOf: event on: data ] | ||
] | ||
] | ||
|
||
{ #category : 'system startup' } | ||
ZnEventToLogRecordAdapter >> stopListeners [ | ||
|
||
subscriptions do: [:subscription | ZnLogEvent announcer removeSubscription: subscription] | ||
] | ||
|
||
{ #category : 'system startup' } | ||
ZnEventToLogRecordAdapter >> subscribeToEventsOf: anEventType andDo: aBlock [ | ||
|
||
subscriptions add: ( ZnLogEvent announcer when: anEventType do: aBlock for: self ) | ||
] |