Skip to content

Commit

Permalink
WIP passes tests
Browse files Browse the repository at this point in the history
Fixes #349.
  • Loading branch information
Gavin Norman committed Aug 2, 2018
1 parent 05262d3 commit 4869547
Show file tree
Hide file tree
Showing 2 changed files with 318 additions and 44 deletions.
113 changes: 69 additions & 44 deletions integrationtest/turtleenv/main.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
Test of the abstract turtle node extension.
Test of the turtle swarm node extension.
Copyright:
Copyright (c) 2018 dunnhumby Germany GmbH. All rights reserved.
Expand All @@ -13,87 +13,110 @@
module integrationtest.turtleenv.main;

import swarm.neo.AddrPort;
import turtle.env.model.Node;
import turtle.env.model.TestNode;
import ocean.transition;
import ocean.util.test.DirectorySandbox;
import ocean.core.Test;
import ocean.io.device.File;
import swarm.node.connection.ConnectionHandler;

/// Node used to the turtle test
private class TurtleNode
/// Connection handler stub
private class MyConnHandler : ISwarmConnectionHandler
{
/// Address and the port of the node
AddrPort addrport;
AddrPort neo_address;
public this ( FinalizeDg finalize_dg, ConnectionSetupParams setup )
{
super(finalize_dg, setup);
}

this (AddrPort addrport)
protected override void handleCommand ( )
{
this.addrport = addrport;
this.neo_address = AddrPort(this.addrport.address());
this.neo_address.port = cast(ushort)(this.addrport.port() + 100);
}
}

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

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

***********************************************************************/
static const name = "dummy";
static const Command command = Command.init;

override protected TurtleNode createNode ( AddrPort addrport )
{
return new TurtleNode(addrport);
override void handle ( RequestOnConn connection, Object resources,
Const!(void)[] init_payload )
{
}
}

/***********************************************************************
/***************************************************************************
Returns:
address/port on which node is listening
Constructor
***********************************************************************/
Params:
node = node addres & port
neo_port = port of neo listener (same address as above)
conn_setup_params = connection handler constructor arguments
options = options for the neo node and connection handlers
backlog = (see ISelectListener ctor)
override public AddrPort node_addrport ( )
***************************************************************************/

public this ( AddrPort node )
{
assert(this.node);
return this.node.addrport;
ushort neo_port = node.port + 100;
auto epoll = new EpollSelectDispatcher;
auto setup = new ConnectionSetupParams;
setup.epoll = epoll;
Options options;
options.epoll = epoll;
options.credentials_map["test"] = Key.init;
options.requests.addHandler!(DummyRequest);
int backlog = 1024;
super(node, neo_port, setup, options, backlog);
}

/***********************************************************************
Fake node service stop implementation.
Removes all data from the fake node service.
***********************************************************************/

protected override void stopImpl ( )
override public void clear ( )
{
}

/***********************************************************************
/***************************************************************************
Removes all data from the fake node service.
Returns:
identifier string for this node
***********************************************************************/
***************************************************************************/

override public void clear ( )
protected override cstring id ( )
{
return "turtleNode";
}

/***********************************************************************
/***************************************************************************
Suppresses log output from the fake node if used version of proto
supports it.
Scope allocates a request resource acquirer backed by the protected
`shared_resources`. (Passed as a generic Object to avoid templatising
this class and others that depend on it.)
***********************************************************************/
Params:
handle_request_dg = delegate that receives a resources acquirer and
initiates handling of a request
***************************************************************************/

override public void log_errors ( bool log_errors )
protected override void getResourceAcquirer (
void delegate ( Object resource_acquirer ) handle_request_dg )
{
static if (is(typeof(this.node.log_errors(log_errors))))
this.node.log_errors(log_errors);
}
}

Expand All @@ -105,8 +128,10 @@ void main()
scope (success)
sandbox.remove();

auto node = new TestNode();
node.start("127.0.0.1", 10000);
AddrPort addr;
addr.setAddress("127.0.0.1");
addr.port = 10000;
auto node = new MyNode(addr);
node.genConfigFiles(".");

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

0 comments on commit 4869547

Please sign in to comment.