Skip to content

Commit

Permalink
Add an example executing remote code using scripter [feenkcom/gtoolki…
Browse files Browse the repository at this point in the history
  • Loading branch information
chisandrei committed Aug 26, 2024
1 parent 3a59b6e commit 536ce26
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Class {
#name : #GtRemoteGemStonePlaygroundExamples,
#superclass : #Object,
#instVars : [
'theExternalSnippetContext'
'theExternalSnippetContext',
'server'
],
#category : #'GToolkit-RemoteExamples-GemStone'
}
Expand Down Expand Up @@ -95,6 +96,27 @@ GtRemoteGemStonePlaygroundExamples >> pageToolWithSnippetWithTest1Session [
^ pageTool
]

{ #category : #examples }
GtRemoteGemStonePlaygroundExamples >> pageToolWithSnippetWithTestDefaultSessionAndBasicCode [
<gtExample>
| page pageTool snippet |

page := LePage new
addSnippet: (snippet := LeGemStoneSnippet new
code: '1+1';
sessionName: 'test:default');
yourself.

self assert: snippet sessionName equals: 'test:default'.
self assert: snippet code equals: '1+1'.

pageTool := LePagePhlowTool new
page: page.
pageTool externalSnippetContext: self externalSnippetContext.

^ pageTool
]

{ #category : #examples }
GtRemoteGemStonePlaygroundExamples >> pageWithEmptySnippetWithNoSession [
<gtExample>
Expand All @@ -109,6 +131,56 @@ GtRemoteGemStonePlaygroundExamples >> pageWithEmptySnippetWithNoSession [
^ page
]

{ #category : #examples }
GtRemoteGemStonePlaygroundExamples >> playgroundPageWithConnectedGemStone [
"Example with a GemStone snippet with a session name,
and a registry with no session and a configured connector."
<gtExample>
| pageTool scripter |

self runningServer.

self assert: self gemstoneSessionRegistry hasConnectors.
self assert: self gemstoneSessionRegistry hasSessions.

pageTool := self pageToolWithSnippetWithTestDefaultSessionAndBasicCode.

scripter := self scripterForPageTool: pageTool.

self
assertGemStoneSessionLabel: 'test'
for: scripter.

self assert: self gemstoneSessionRegistry sessions size equals: 1.
self assert: self gemstoneSessionRegistry sessions values first isRunning.
self
assert: self gemstoneSessionRegistry sessions values first name
equals: 'test:default'.

^ scripter
]

{ #category : #examples }
GtRemoteGemStonePlaygroundExamples >> playgroundPageWithConnectedGemStone_runAsyncComputation [
"Example with a GemStone snippet with a session name,
and a registry with no session and a configured connector."
<gtExample>
| scripter |

scripter := self playgroundPageWithConnectedGemStone.

self withEnabledAutomaticReplaceDo: [
scripter click
label: 'Click on play and inspect button';
// GtSourceCoderDoItAndGoActionId;
play ].

scripter pager
assertPageCountIs: 2.

^ scripter
]

{ #category : #examples }
GtRemoteGemStonePlaygroundExamples >> playgroundWithSnippetWithNoSessionNameOnEmptyRegistry [
"Example with a GemStone snippet without a session name,
Expand Down Expand Up @@ -200,6 +272,29 @@ GtRemoteGemStonePlaygroundExamples >> playgroundWithSnippetWithSessionNameOnRegi
^ scripter
]

{ #category : #'examples - setup/tear down' }
GtRemoteGemStonePlaygroundExamples >> runningServer [
"Answer a running server.
This assumes:
- The GemStone server is running with Gt loaded
- Default usernames and passwords
- The library is available in {imageDirectory}/remote-gemstone/3.7.0"
<gtExample>
<after: #stopServer>
| connector |

server ifNotNil: [ ^ server ].

connector := GtRemoteGemstoneExamplesSessionBuilder createConnectorNamed: 'test'.
self gemstoneSessionRegistry
connectorNamed: 'test'
ifPresent: [ :aConnector | Error signal: 'Connector already present']
ifAbsent: [ self gemstoneSessionRegistry connectors
at: 'test' put: connector ].
^ server := self gemstoneSessionRegistry
newSessionOrDefaultWithConnector: connector
]

{ #category : #accessing }
GtRemoteGemStonePlaygroundExamples >> scripter [
^ BlScripter new
Expand All @@ -210,7 +305,36 @@ GtRemoteGemStonePlaygroundExamples >> scripterForPageTool: aPageTool [
| scripter |
scripter := self scripter.
scripter
model: aPageTool page;
element: aPageTool asElement.
model: aPageTool;
element: (GtPager createWrappedOn: aPageTool asElement).
^ scripter
]

{ #category : #'examples - setup/tear down' }
GtRemoteGemStonePlaygroundExamples >> stopServer [

server ifNotNil:
[ server stop.
server := nil ].
]

{ #category : #utils }
GtRemoteGemStonePlaygroundExamples >> withAutomaticReplaceSetTo: aBoolean do: aBlock [
| currentValue |
currentValue := GtGemStoneAsyncEvaluationPhlowTool replacePaneContentAutomatically.

GtGemStoneAsyncEvaluationPhlowTool replacePaneContentAutomatically: aBoolean.
aBlock ensure: [
GtGemStoneAsyncEvaluationPhlowTool replacePaneContentAutomatically: currentValue ].

]

{ #category : #utils }
GtRemoteGemStonePlaygroundExamples >> withDisabledAutomaticReplaceDo: aBlock [
self withAutomaticReplaceSetTo: false do: aBlock
]

{ #category : #utils }
GtRemoteGemStonePlaygroundExamples >> withEnabledAutomaticReplaceDo: aBlock [
self withAutomaticReplaceSetTo: true do: aBlock
]
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GtRemoteGemStoneSessionAsyncExamples >> stopServer [
server := nil ].
]

{ #category : #examples }
{ #category : #'examples - basic' }
GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_interruptAndCancelComputation [
<gtExample>
| evaluatorPromise executionContext interruptResultData rawEvaluationResultData errorEvaluationResultData errorEvaluationResult evaluationResult terminateEvaluationResultData |
Expand Down Expand Up @@ -68,7 +68,7 @@ GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_interruptA
^ evaluationResult
]

{ #category : #examples }
{ #category : #'examples - basic' }
GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_interruptAndResumeComputation [
<gtExample>
| evaluatorPromise executionContext interruptResultData rawEvaluationResultData resumeEvaluationResult errorEvaluationResultData errorEvaluationResult evaluationResult resumedEvaluationResultData |
Expand Down Expand Up @@ -112,7 +112,7 @@ GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_interruptA
^ evaluationResult
]

{ #category : #examples }
{ #category : #'examples - basic' }
GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_returnLegacy [
<gtExample>
| evaluatorPromise executionContext rawEvaluationResultData evaluationResult |
Expand Down Expand Up @@ -143,7 +143,7 @@ GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_returnLega
^ evaluationResult
]

{ #category : #examples }
{ #category : #'examples - basic' }
GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_returnProxy [
<gtExample>
| evaluatorPromise executionContext rawEvaluationResultData evaluationResult |
Expand Down Expand Up @@ -181,7 +181,7 @@ GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_returnProx
^ evaluationResult
]

{ #category : #examples }
{ #category : #'examples - basic' }
GtRemoteGemStoneSessionAsyncExamples >> testManualResolutionAsyncCall_terminateComputation [
<gtExample>
| evaluatorPromise executionContext terminatedResultData rawEvaluationResultData evaluationResult |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ GtRemoteGemstoneExamplesSessionBuilder class >> createAndStartSession [
^ self new createAndStartSession
]

{ #category : #accessing }
GtRemoteGemstoneExamplesSessionBuilder class >> createAndStartSessionForConnector: aConnector [
^ self new
createAndStartSessionForConnector: aConnector
]

{ #category : #accessing }
GtRemoteGemstoneExamplesSessionBuilder class >> createConnectorNamed: aConnectorName [
^ self new
Expand All @@ -22,6 +28,14 @@ GtRemoteGemstoneExamplesSessionBuilder >> createAndStartSession [
yourself
]

{ #category : #accessing }
GtRemoteGemstoneExamplesSessionBuilder >> createAndStartSessionForConnector: aConnector [
^ (GtGemStoneSession new
connector: aConnector)
connect;
yourself
]

{ #category : #accessing }
GtRemoteGemstoneExamplesSessionBuilder >> createConnector [
^ self createConnectorNamed: nil
Expand Down

0 comments on commit 536ce26

Please sign in to comment.