Skip to content

Commit

Permalink
Convert assert -> verify/enforce in neo code
Browse files Browse the repository at this point in the history
Fixes #152.
  • Loading branch information
Gavin Norman authored and nemanja-boric-sociomantic committed Jun 7, 2018
1 parent 303d339 commit c032b15
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 169 deletions.
5 changes: 3 additions & 2 deletions src/dhtproto/client/internal/NodeHashRanges.d
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private class NodeHashRangesBase
import swarm.neo.client.ConnectionSet;
import swarm.util.Hash : isWithinNodeResponsibility;
import ocean.core.array.Mutation : sort;
import ocean.core.Verify;

/// Value of the next created NodeHashRange's order field.
private static ulong order_counter;
Expand Down Expand Up @@ -309,7 +310,7 @@ private class NodeHashRangesBase
// Update an existing node.
if ( auto nhr = addr.cmp_id in this.node_hash_ranges )
{
assert(nhr.addr == addr);
verify(nhr.addr == addr);
nhr.hash_range = NodeHashRange.HashRange(min, max);
nhr.order = order_counter++;
}
Expand Down Expand Up @@ -352,7 +353,7 @@ private class NodeHashRangesBase

bool sortPred ( NodeHashRange e1, NodeHashRange e2 )
{
assert(e1.order != e2.order);
verify(e1.order != e2.order);
return e1.order > e2.order;
}

Expand Down
3 changes: 2 additions & 1 deletion src/dhtproto/client/internal/SharedResources.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class SharedResources
import swarm.neo.client.ConnectionSet;
import ocean.util.container.pool.FreeList;
import ocean.core.TypeConvert : downcast;
import ocean.core.Verify;
import ocean.io.compress.Lzo;
import swarm.neo.util.MessageFiber;
import swarm.neo.util.VoidBufferAsArrayOf;
Expand Down Expand Up @@ -59,7 +60,7 @@ public final class SharedResources
public static SharedResources fromObject ( Object obj )
{
auto shared_resources = downcast!(SharedResources)(obj);
assert(shared_resources !is null);
verify(shared_resources !is null);
return shared_resources;
}

Expand Down
89 changes: 31 additions & 58 deletions src/dhtproto/client/mixins/NeoSupport.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ template NeoSupport ( )
import swarm.neo.client.mixins.Controllers;
import swarm.neo.client.request_options.RequestOptions;
import ocean.core.SmartUnion;
import ocean.core.Verify;

/***********************************************************************
Expand Down Expand Up @@ -614,7 +615,7 @@ template NeoSupport ( )
public void waitAllHashRangesKnown ( )
{
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

auto old_user_conn_notifier = this.outer.user_conn_notifier;

Expand Down Expand Up @@ -742,14 +743,10 @@ template NeoSupport ( )

public void put ( cstring channel, hash_t key, Const!(void)[] value,
Neo.Put.Notifier user_notifier )
in
{
assert(user_notifier !is null);
}
body
{
verify(user_notifier !is null);
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

bool finished;

Expand All @@ -767,7 +764,7 @@ template NeoSupport ( )
this.outer.neo.put(channel, key, value, &notifier);
if ( !finished ) // if request not completed, suspend
task.suspend();
assert(finished);
verify(finished);
}

/***********************************************************************
Expand Down Expand Up @@ -813,7 +810,7 @@ template NeoSupport ( )
public PutResult put ( cstring channel, hash_t key, Const!(void)[] value )
{
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

enum FinishedStatus
{
Expand Down Expand Up @@ -853,7 +850,7 @@ template NeoSupport ( )
this.outer.neo.put(channel, key, value, &notifier);
if ( state == state.None ) // if request not completed, suspend
task.suspend();
assert(state != state.None);
verify(state != state.None);

PutResult res;
res.succeeded = state == state.Succeeded;
Expand All @@ -876,14 +873,10 @@ template NeoSupport ( )

public void get ( cstring channel, hash_t key,
Neo.Get.Notifier user_notifier )
in
{
assert(user_notifier !is null);
}
body
{
verify(user_notifier !is null);
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

bool finished;

Expand All @@ -901,7 +894,7 @@ template NeoSupport ( )
this.outer.neo.get(channel, key, &notifier);
if ( !finished ) // if request not completed, suspend
task.suspend();
assert(finished);
verify(finished);
}

/***********************************************************************
Expand Down Expand Up @@ -957,7 +950,7 @@ template NeoSupport ( )
public GetResult get ( cstring channel, hash_t key, ref void[] value )
{
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

enum FinishedStatus
{
Expand Down Expand Up @@ -1003,7 +996,7 @@ template NeoSupport ( )
this.outer.neo.get(channel, key, &notifier);
if ( state == state.None ) // if request not completed, suspend
task.suspend();
assert(state != state.None);
verify(state != state.None);

res.succeeded = state == state.Succeeded;
return res;
Expand All @@ -1025,14 +1018,10 @@ template NeoSupport ( )

public void update ( cstring channel, hash_t key,
Neo.Update.Notifier user_notifier )
in
{
assert(user_notifier !is null);
}
body
{
verify(user_notifier !is null);
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

bool finished;

Expand Down Expand Up @@ -1061,7 +1050,7 @@ template NeoSupport ( )
this.outer.neo.update(channel, key, &notifier);
if ( !finished ) // if request not completed, suspend
task.suspend();
assert(finished);
verify(finished);
}

/***********************************************************************
Expand All @@ -1080,14 +1069,10 @@ template NeoSupport ( )

public void exists ( cstring channel, hash_t key,
Neo.Exists.Notifier user_notifier )
in
{
assert(user_notifier !is null);
}
body
{
verify(user_notifier !is null);
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

bool finished;

Expand All @@ -1106,7 +1091,7 @@ template NeoSupport ( )
this.outer.neo.exists(channel, key, &notifier);
if ( !finished ) // if request not completed, suspend
task.suspend();
assert(finished);
verify(finished);
}

/***********************************************************************
Expand Down Expand Up @@ -1158,7 +1143,7 @@ template NeoSupport ( )
public ExistsResult exists ( cstring channel, hash_t key )
{
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

bool finished;
ExistsResult res;
Expand Down Expand Up @@ -1199,7 +1184,7 @@ template NeoSupport ( )
this.outer.neo.exists(channel, key, &notifier);
if ( !finished ) // if request not completed, suspend
task.suspend();
assert(finished);
verify(finished);

return res;
}
Expand All @@ -1220,14 +1205,10 @@ template NeoSupport ( )

public void remove ( cstring channel, hash_t key,
Neo.Remove.Notifier user_notifier )
in
{
assert(user_notifier !is null);
}
body
{
verify(user_notifier !is null);
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

bool finished;

Expand All @@ -1246,7 +1227,7 @@ template NeoSupport ( )
this.outer.neo.remove(channel, key, &notifier);
if ( !finished ) // if request not completed, suspend
task.suspend();
assert(finished);
verify(finished);
}

/***********************************************************************
Expand Down Expand Up @@ -1298,7 +1279,7 @@ template NeoSupport ( )
public RemoveResult remove ( cstring channel, hash_t key )
{
auto task = Task.getThis();
assert(task, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

enum FinishedStatus
{
Expand Down Expand Up @@ -1343,7 +1324,7 @@ template NeoSupport ( )
this.outer.neo.remove(channel, key, &notifier);
if ( state == state.None ) // if request not completed, suspend
task.suspend();
assert(state != state.None);
verify(state != state.None);

res.succeeded = state == state.Succeeded;
return res;
Expand Down Expand Up @@ -1537,7 +1518,7 @@ template NeoSupport ( )
public GetAllFruct getAll ( cstring channel, ref void[] record_buffer )
{
auto task = Task.getThis();
assert(task !is null,
verify(task !is null,
"This method may only be called from inside a Task");

GetAllFruct res;
Expand Down Expand Up @@ -1695,7 +1676,7 @@ template NeoSupport ( )
public GetChannelsFruct getChannels ( ref mstring channel_buffer )
{
auto task = Task.getThis();
assert(task !is null,
verify(task !is null,
"This method may only be called from inside a Task");

GetChannelsFruct res;
Expand Down Expand Up @@ -1747,7 +1728,7 @@ template NeoSupport ( )
public RemoveChannelResult removeChannel ( cstring channel )
{
auto task = Task.getThis();
assert(task !is null, "This method may only be called from inside a Task");
verify(task !is null, "This method may only be called from inside a Task");

enum FinishedStatus
{
Expand Down Expand Up @@ -1785,7 +1766,7 @@ template NeoSupport ( )
this.outer.neo.removeChannel(channel, &notifier);
if ( state == state.None ) // if request not completed, suspend
task.suspend();
assert(state != state.None);
verify(state != state.None);

RemoveChannelResult res;
res.succeeded = state == state.Succeeded;
Expand Down Expand Up @@ -1846,12 +1827,8 @@ template NeoSupport ( )

private void neoInit ( Neo.Config config,
Neo.DhtConnectionNotifier user_conn_notifier )
in
{
assert(user_conn_notifier !is null);
}
body
{
verify(user_conn_notifier !is null);
this.user_conn_notifier = user_conn_notifier;

this.shared_resources = new SharedResources;
Expand Down Expand Up @@ -1888,12 +1865,8 @@ template NeoSupport ( )

private void neoInit ( cstring auth_name, ubyte[] auth_key,
Neo.DhtConnectionNotifier user_conn_notifier )
in
{
assert(user_conn_notifier !is null);
}
body
{
verify(user_conn_notifier !is null);
this.user_conn_notifier = user_conn_notifier;

this.shared_resources = new SharedResources;
Expand Down
5 changes: 3 additions & 2 deletions src/dhtproto/client/request/internal/GetAll.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module dhtproto.client.request.internal.GetAll;

import ocean.transition;
import ocean.util.log.Logger;
import ocean.core.Verify;

/*******************************************************************************
Expand Down Expand Up @@ -369,8 +370,8 @@ private scope class GetAllHandler

this.request_event_dispatcher.eventLoop(this.conn);

assert(controller.fiber.finished());
assert(reader.fiber.finished());
verify(controller.fiber.finished());
verify(reader.fiber.finished());
}

/***************************************************************************
Expand Down
5 changes: 3 additions & 2 deletions src/dhtproto/client/request/internal/Mirror.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module dhtproto.client.request.internal.Mirror;

import ocean.transition;
import ocean.util.log.Logger;
import ocean.core.Verify;

/*******************************************************************************
Expand Down Expand Up @@ -326,8 +327,8 @@ private scope class MirrorHandler

this.request_event_dispatcher.eventLoop(this.conn);

assert(controller.fiber.finished());
assert(reader.fiber.finished());
verify(controller.fiber.finished());
verify(reader.fiber.finished());
}

/***************************************************************************
Expand Down
7 changes: 4 additions & 3 deletions src/dhtproto/client/request/internal/Update.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module dhtproto.client.request.internal.Update;

import ocean.transition;
import ocean.util.log.Logger;
import ocean.core.Verify;

/*******************************************************************************
Expand Down Expand Up @@ -450,7 +451,7 @@ private struct FirstROCHandler
auto value = conn.message_parser.getArray!(void)(payload);

this.context.shared_working.original_hash = Fnv1a(value);
assert(this.context.shared_working.updated_value is null);
verify(this.context.shared_working.updated_value is null);
this.context.shared_working.updated_value =
acquired_resources.getVoidBuffer();

Expand Down Expand Up @@ -580,8 +581,8 @@ private struct FirstROCHandler
// the buffer for the updated value. If this ROC were to simply exit at
// this stage, this buffer would be relinquished.)
auto event = conn.nextEvent(conn.NextEventFlags.init);
assert(event.active == event.Active.resumed);
assert(event.resumed.code == Update.SecondROCFinished);
verify(event.active == event.Active.resumed);
verify(event.resumed.code == Update.SecondROCFinished);

// If the request on the second request-on-conn failed, the result code
// will already have been set in the shared working data.
Expand Down
Loading

0 comments on commit c032b15

Please sign in to comment.