Skip to content

Commit 4869547

Browse files
author
Gavin Norman
committed
WIP passes tests
Fixes #349.
1 parent 05262d3 commit 4869547

File tree

2 files changed

+318
-44
lines changed

2 files changed

+318
-44
lines changed

integrationtest/turtleenv/main.d

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
3-
Test of the abstract turtle node extension.
3+
Test of the turtle swarm node extension.
44
55
Copyright:
66
Copyright (c) 2018 dunnhumby Germany GmbH. All rights reserved.
@@ -13,87 +13,110 @@
1313
module integrationtest.turtleenv.main;
1414

1515
import swarm.neo.AddrPort;
16-
import turtle.env.model.Node;
16+
import turtle.env.model.TestNode;
17+
import ocean.transition;
1718
import ocean.util.test.DirectorySandbox;
1819
import ocean.core.Test;
1920
import ocean.io.device.File;
21+
import swarm.node.connection.ConnectionHandler;
2022

21-
/// Node used to the turtle test
22-
private class TurtleNode
23+
/// Connection handler stub
24+
private class MyConnHandler : ISwarmConnectionHandler
2325
{
24-
/// Address and the port of the node
25-
AddrPort addrport;
26-
AddrPort neo_address;
26+
public this ( FinalizeDg finalize_dg, ConnectionSetupParams setup )
27+
{
28+
super(finalize_dg, setup);
29+
}
2730

28-
this (AddrPort addrport)
31+
protected override void handleCommand ( )
2932
{
30-
this.addrport = addrport;
31-
this.neo_address = AddrPort(this.addrport.address());
32-
this.neo_address.port = cast(ushort)(this.addrport.port() + 100);
3333
}
3434
}
3535

36-
/// The turlte TurtleNode class
37-
private class TestNode : Node!(TurtleNode, "turtleNode")
36+
/// Concrete turtle swarm node class
37+
private class MyNode : TestNode!(MyConnHandler)
3838
{
39-
/***********************************************************************
39+
import swarm.neo.node.IRequestHandler : IRequest;
4040

41-
Creates a fake node at the specified address/port.
42-
43-
Params:
44-
node_item = address/port
41+
/// Dummy request handler class. Required by base class
42+
private static class DummyRequest : IRequest
43+
{
44+
import swarm.neo.node.RequestOnConn;
45+
import swarm.neo.request.Command;
4546

46-
***********************************************************************/
47+
static const name = "dummy";
48+
static const Command command = Command.init;
4749

48-
override protected TurtleNode createNode ( AddrPort addrport )
49-
{
50-
return new TurtleNode(addrport);
50+
override void handle ( RequestOnConn connection, Object resources,
51+
Const!(void)[] init_payload )
52+
{
53+
}
5154
}
5255

53-
/***********************************************************************
56+
/***************************************************************************
5457
55-
Returns:
56-
address/port on which node is listening
58+
Constructor
5759
58-
***********************************************************************/
60+
Params:
61+
node = node addres & port
62+
neo_port = port of neo listener (same address as above)
63+
conn_setup_params = connection handler constructor arguments
64+
options = options for the neo node and connection handlers
65+
backlog = (see ISelectListener ctor)
5966
60-
override public AddrPort node_addrport ( )
67+
***************************************************************************/
68+
69+
public this ( AddrPort node )
6170
{
62-
assert(this.node);
63-
return this.node.addrport;
71+
ushort neo_port = node.port + 100;
72+
auto epoll = new EpollSelectDispatcher;
73+
auto setup = new ConnectionSetupParams;
74+
setup.epoll = epoll;
75+
Options options;
76+
options.epoll = epoll;
77+
options.credentials_map["test"] = Key.init;
78+
options.requests.addHandler!(DummyRequest);
79+
int backlog = 1024;
80+
super(node, neo_port, setup, options, backlog);
6481
}
6582

6683
/***********************************************************************
6784
68-
Fake node service stop implementation.
85+
Removes all data from the fake node service.
6986
7087
***********************************************************************/
7188

72-
protected override void stopImpl ( )
89+
override public void clear ( )
7390
{
7491
}
7592

76-
/***********************************************************************
93+
/***************************************************************************
7794
78-
Removes all data from the fake node service.
95+
Returns:
96+
identifier string for this node
7997
80-
***********************************************************************/
98+
***************************************************************************/
8199

82-
override public void clear ( )
100+
protected override cstring id ( )
83101
{
102+
return "turtleNode";
84103
}
85104

86-
/***********************************************************************
105+
/***************************************************************************
87106
88-
Suppresses log output from the fake node if used version of proto
89-
supports it.
107+
Scope allocates a request resource acquirer backed by the protected
108+
`shared_resources`. (Passed as a generic Object to avoid templatising
109+
this class and others that depend on it.)
90110
91-
***********************************************************************/
111+
Params:
112+
handle_request_dg = delegate that receives a resources acquirer and
113+
initiates handling of a request
114+
115+
***************************************************************************/
92116

93-
override public void log_errors ( bool log_errors )
117+
protected override void getResourceAcquirer (
118+
void delegate ( Object resource_acquirer ) handle_request_dg )
94119
{
95-
static if (is(typeof(this.node.log_errors(log_errors))))
96-
this.node.log_errors(log_errors);
97120
}
98121
}
99122

@@ -105,8 +128,10 @@ void main()
105128
scope (success)
106129
sandbox.remove();
107130

108-
auto node = new TestNode();
109-
node.start("127.0.0.1", 10000);
131+
AddrPort addr;
132+
addr.setAddress("127.0.0.1");
133+
addr.port = 10000;
134+
auto node = new MyNode(addr);
110135
node.genConfigFiles(".");
111136

112137
test!("==")(File.get("turtleNode.nodes"), "127.0.0.1:10000\n");

0 commit comments

Comments
 (0)