[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28590 - in gnunet-java: . doc src/org/gnunet/consensus src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28590 - in gnunet-java: . doc src/org/gnunet/consensus src/org/gnunet/construct src/org/gnunet/mesh src/org/gnunet/mq src/org/gnunet/util test/org/gnunet/core test/org/gnunet/mesh test/org/gnunet/statistics test/org/gnunet/util |
Date: |
Tue, 13 Aug 2013 23:49:15 +0200 |
Author: dold
Date: 2013-08-13 23:49:15 +0200 (Tue, 13 Aug 2013)
New Revision: 28590
Added:
gnunet-java/test/org/gnunet/util/SchedulerExceptionTest.java
gnunet-java/test/org/gnunet/util/SchedulerTimeoutTest.java
Removed:
gnunet-java/doc/consensus.pdf
Modified:
gnunet-java/ISSUES
gnunet-java/src/org/gnunet/consensus/ConcludeDoneMessage.java
gnunet-java/src/org/gnunet/consensus/Consensus.java
gnunet-java/src/org/gnunet/construct/MsgMap.txt
gnunet-java/src/org/gnunet/mesh/Mesh.java
gnunet-java/src/org/gnunet/mq/ClientMessageQueue.java
gnunet-java/src/org/gnunet/util/AbsoluteTime.java
gnunet-java/src/org/gnunet/util/AbsoluteTimeMessage.java
gnunet-java/src/org/gnunet/util/Configuration.java
gnunet-java/src/org/gnunet/util/Connection.java
gnunet-java/src/org/gnunet/util/RelativeTime.java
gnunet-java/src/org/gnunet/util/RelativeTimeMessage.java
gnunet-java/src/org/gnunet/util/Scheduler.java
gnunet-java/test/org/gnunet/core/CoreTest.java
gnunet-java/test/org/gnunet/mesh/MeshTest.java
gnunet-java/test/org/gnunet/statistics/StatisticsTest.java
gnunet-java/test/org/gnunet/util/TimeTest.java
Log:
- mq,mesh,consensus,millisecond time
Modified: gnunet-java/ISSUES
===================================================================
--- gnunet-java/ISSUES 2013-08-13 21:38:16 UTC (rev 28589)
+++ gnunet-java/ISSUES 2013-08-13 21:49:15 UTC (rev 28590)
@@ -1,65 +0,0 @@
-* does GNUNET_FORCE_LOG work for log_from?
- * set-api log messages dlog messages do not appear ...
-
-* consensus profiler and set shutdown:
- * set is destroyed (shutdown!) before consensus, consensus still has listener
-
-* i hit the problem of cyclic IBFs again ...
- * identical subsequent keys => stop
- * more than ibf->size elements decoded => stop
- * similar rules apply to strata estimators
-
-* running test_set_api is *the* way to trigger all kinds of mesh assertions!
- * and consensus currently *seems* to only fail due to mesh assertions (via
set)
-
-* worst bug i've had in a long time:
- https://gnunet.org/bugs/view.php?id=2967
- * see 1st comment: I can't find any other reason than mesh!
-
-* discuss mesh tunnel auto reconnect
- * bad for state-ful protocols
- * shouldn't be transparent to the user
- * there's almost no way for the connection to the service to be lost without
- the mesh service crashing
-
-* discuss set api issues from the bug tracker
- * when is op cancel necessary?
- * I got into the same problem as you (consensus!), so maybe the current API
*is* bad ...
- * listener auto reconnect?
-
-* in consensus, we need to present all elements to the client at the end of
conclude
- * => set now as GNUNET_SET_iterate
-
-* sounds easier than it is: iterating over a GNUNET_SET's elements.
- * handling canceling for iterating over a set?
- * flow control? memory overhead for queue?
- * any idea how to implement iteration "better"?
-
-* mq vs RequestQueue
- * totally different approach
- * queueing messages vs maintaining requests
- * the latter is too complicated/contrived, let's go for mq!
-
-* consensus in java: how would you represent / pass an
- element w.r.t. missing const-correctness in java?
-
-* context: how to do it in java?
- * plain Object vs Tunnel<T>
- * latter is nicer, currently implemented
-
-mq for *implementing* the mesh api:
-* observations about sending messages:
- * messages are virtually never constructed in the ntr callback
- * message construction is never costly
- * the only reason I see for using ntr is that you can directly write
- to a buffer. This argument does not apply to gnunet-java
(org.gnunet.construct)
- * does not apply to mesh; mesh does not even use the message size
- * in java: notify transmit really clunky, why use it?
-
-* currently, in gnunet-java a mesh tunnel *is* a message queue with an
additional notifySendReady
-* optional to use, otherwise queued messages are sent when mesh allows it
-
-* something does not let me run the consensus profiler when on a train ....
- Jul 24 11:33:28-647361 testbed-api-topology-25801 WARNING Error while
establishing a link: 0x4: Timeout while acquiring HELLO of peer 5MBM -- Retrying
- * fixed, but why is this not the default?
-
Deleted: gnunet-java/doc/consensus.pdf
===================================================================
(Binary files differ)
Modified: gnunet-java/src/org/gnunet/consensus/ConcludeDoneMessage.java
===================================================================
--- gnunet-java/src/org/gnunet/consensus/ConcludeDoneMessage.java
2013-08-13 21:38:16 UTC (rev 28589)
+++ gnunet-java/src/org/gnunet/consensus/ConcludeDoneMessage.java
2013-08-13 21:49:15 UTC (rev 28590)
@@ -1,6 +1,7 @@
package org.gnunet.consensus;
+import org.gnunet.construct.MessageUnion;
import org.gnunet.construct.UnionCase;
/**
@@ -8,5 +9,5 @@
* Direction: service -> client
*/
@UnionCase(525)
-public class ConcludeDoneMessage {
+public class ConcludeDoneMessage implements MessageUnion {
}
Modified: gnunet-java/src/org/gnunet/consensus/Consensus.java
===================================================================
--- gnunet-java/src/org/gnunet/consensus/Consensus.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/src/org/gnunet/consensus/Consensus.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -85,6 +85,12 @@
this.newElementCallback = newElementCallback;
}
+ /**
+ * Insert an element into the consensus set.
+ *
+ * @param element element to insert in the consnesus
+ * @param idc called when the element has been sent to the service
+ */
public void insertElement (ConsensusElement element, final
InsertDoneCallback idc) {
InsertElementMessage m = new InsertElementMessage();
m.element_data = element.data;
@@ -99,17 +105,27 @@
client_mq.send(ev);
}
+ /**
+ * We are done with inserting new elements into the consensus;
+ * try to conclude the consensus within a given time window.
+ * After conclude has been called, no further elements may be
+ * inserted by the client.
+ * @param concludeCallback called when the consensus has concluded
+ */
public void conclude(ConcludeCallback concludeCallback) {
if (null == concludeCallback)
throw new AssertionError("conclude with empty callback");
if (null != this.concludeCallback)
throw new AssertionError("called conclude twice");
this.concludeCallback = concludeCallback;
+ ConcludeMessage m = new ConcludeMessage();
+ client_mq.send(m);
}
/**
- * Destroy a consensus handle (free all state associated with
- * it, no longer call any of the callbacks).
+ * Destroy a consensus handle.
+ * Free all state associated with
+ * it, no longer call any of the callbacks.
*/
public void destroy() {
client_mq.destroy();
Modified: gnunet-java/src/org/gnunet/construct/MsgMap.txt
===================================================================
--- gnunet-java/src/org/gnunet/construct/MsgMap.txt 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/src/org/gnunet/construct/MsgMap.txt 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -1,7 +1,6 @@
org.gnunet.util.Resolver$Address|0=org.gnunet.util.Resolver$TextualAddress
org.gnunet.util.Resolver$Address|1=org.gnunet.util.Resolver$NumericAddress
org.gnunet.util.GnunetMessage$Body|68=org.gnunet.core.DisconnectNotifyMessage
-org.gnunet.util.GnunetMessage$Body|275=org.gnunet.mesh.PeerAddMessage
org.gnunet.util.GnunetMessage$Body|274=org.gnunet.mesh.TunnelDestroyMessage
org.gnunet.util.GnunetMessage$Body|1=org.gnunet.util.TestMessage
org.gnunet.util.GnunetMessage$Body|70=org.gnunet.core.NotifyInboundTrafficMessage
@@ -12,10 +11,8 @@
org.gnunet.util.GnunetMessage$Body|4=org.gnunet.util.Resolver$GetMessage
org.gnunet.util.GnunetMessage$Body|65=org.gnunet.core.InitReplyMessage
org.gnunet.util.GnunetMessage$Body|5=org.gnunet.util.Resolver$ResolverResponse
-org.gnunet.util.GnunetMessage$Body|277=org.gnunet.mesh.ConnectPeerByTypeMessage
org.gnunet.util.GnunetMessage$Body|143=org.gnunet.dht.ClientGetMessage
org.gnunet.util.GnunetMessage$Body|67=org.gnunet.core.ConnectNotifyMessage
-org.gnunet.util.GnunetMessage$Body|276=org.gnunet.mesh.PeerDeleteMessage
org.gnunet.util.GnunetMessage$Body|142=org.gnunet.dht.ClientPutMessage
org.gnunet.util.GnunetMessage$Body|76=org.gnunet.core.SendMessage
org.gnunet.util.GnunetMessage$Body|286=org.gnunet.mesh.LocalAckMessage
@@ -23,10 +20,8 @@
org.gnunet.util.GnunetMessage$Body|75=org.gnunet.core.SendMessageReady
org.gnunet.util.GnunetMessage$Body|153=org.gnunet.dht.MonitorStartStop
org.gnunet.util.GnunetMessage$Body|155=org.gnunet.dht.ClientPutConfirmationMessage
-org.gnunet.util.GnunetMessage$Body|262=org.gnunet.mesh.OriginMessage
org.gnunet.util.GnunetMessage$Body|323=org.gnunet.nse.UpdateMessage
org.gnunet.util.GnunetMessage$Body|260=org.gnunet.mesh.DataMessage
-org.gnunet.util.GnunetMessage$Body|261=org.gnunet.mesh.MulticastMessage
org.gnunet.util.GnunetMessage$Body|321=org.gnunet.nse.StartMessage
org.gnunet.util.GnunetMessage$Body|144=org.gnunet.dht.ClientGetStopMessage
org.gnunet.util.GnunetMessage$Body|145=org.gnunet.dht.ClientResultMessage
@@ -43,5 +38,9 @@
org.gnunet.util.GnunetMessage$Body|374=org.gnunet.transport.RequestConnectMessage
org.gnunet.util.GnunetMessage$Body|173=org.gnunet.statistics.WatchResponseMessage
org.gnunet.util.GnunetMessage$Body|172=org.gnunet.statistics.WatchMessage
+org.gnunet.util.GnunetMessage$Body|524=org.gnunet.consensus.ConcludeMessage
+org.gnunet.util.GnunetMessage$Body|521=org.gnunet.consensus.InsertElementMessage
+org.gnunet.util.GnunetMessage$Body|523=org.gnunet.consensus.NewElementMessage
org.gnunet.util.GnunetMessage$Body|360=org.gnunet.transport.StartMessage
-# generated 2013/04/14 22:27:05
+org.gnunet.construct.MessageUnion|525=org.gnunet.consensus.ConcludeDoneMessage
+# generated 2013/08/13 20:15:12
Modified: gnunet-java/src/org/gnunet/mesh/Mesh.java
===================================================================
--- gnunet-java/src/org/gnunet/mesh/Mesh.java 2013-08-13 21:38:16 UTC (rev
28589)
+++ gnunet-java/src/org/gnunet/mesh/Mesh.java 2013-08-13 21:49:15 UTC (rev
28590)
@@ -116,6 +116,7 @@
* @param <T> type of context data for the tunnel
*/
public class Tunnel<T> extends MessageQueue {
+ private T context;
private final int opt;
public final PeerIdentity peer;
public final int port;
@@ -194,9 +195,17 @@
client_mq.send(mesh_ev);
ack_count -= 1;
}
+
+ public T getContext() {
+ return context;
+ }
+
+ public void setContext(T newContext) {
+ context = newContext;
+ }
+
}
-
private class MeshMessageReceiver extends RunaboutMessageReceiver {
public void visit(TunnelCreateMessage m) {
Tunnel t = new Tunnel(m.otherEnd, m.tunnel_id, m.port,
@@ -235,11 +244,19 @@
@Override
public void handleError() {
- // todo: re-establish all tunnels
+ if (tunnelEndHandler != null) {
+ for (Tunnel t : tunnelMap.values()) {
+ tunnelEndHandler.onTunnelEnd(t);
+ }
+ }
+ tunnelMap.clear();
+ client.reconnect();
+ ClientConnectMessage ccm = new ClientConnectMessage();
+ ccm.apps_list = ports;
+ client_mq.send(ccm);
}
}
-
/**
* Connect to the mesh service.
*
@@ -263,7 +280,6 @@
client_mq.send(ccm);
}
-
/**
* Disconnect from the mesh service.
* All tunnels will be destroyed.
Modified: gnunet-java/src/org/gnunet/mq/ClientMessageQueue.java
===================================================================
--- gnunet-java/src/org/gnunet/mq/ClientMessageQueue.java 2013-08-13
21:38:16 UTC (rev 28589)
+++ gnunet-java/src/org/gnunet/mq/ClientMessageQueue.java 2013-08-13
21:49:15 UTC (rev 28590)
@@ -11,18 +11,15 @@
private final Client client;
private final RunaboutMessageReceiver receiver;
-
public ClientMessageQueue(Client client, RunaboutMessageReceiver receiver)
{
this.client = client;
this.receiver = receiver;
}
-
public ClientMessageQueue(Client client) {
this(client, null);
}
-
@Override
protected void sendImmediate(final Envelope ev) {
int size = Construct.getSize(ev.message);
@@ -40,7 +37,6 @@
});
}
-
@Override
public void destroy() {
Modified: gnunet-java/src/org/gnunet/util/AbsoluteTime.java
===================================================================
--- gnunet-java/src/org/gnunet/util/AbsoluteTime.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/src/org/gnunet/util/AbsoluteTime.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -41,6 +41,11 @@
public final static AbsoluteTime FOREVER = new
AbsoluteTime(Long.MAX_VALUE);
/**
+ * Absolute time value in microseconds.
+ */
+ private final long abs_value_us;
+
+ /**
* Gets the current time.
*
* @return the current time
@@ -49,10 +54,8 @@
return new AbsoluteTime(System.currentTimeMillis());
}
- private final long abs_value;
-
- public AbsoluteTime(final long abs_value) {
- this.abs_value = abs_value;
+ public AbsoluteTime(final long abs_value_us) {
+ this.abs_value_us = abs_value_us;
}
/**
@@ -62,14 +65,14 @@
* @return address@hidden this + duration}
*/
public AbsoluteTime add(RelativeTime duration) {
- if (abs_value == Long.MAX_VALUE
+ if (abs_value_us == Long.MAX_VALUE
|| duration.isForever()) {
return AbsoluteTime.FOREVER;
}
- if (abs_value + duration.getMilliseconds() < abs_value) {
+ if (abs_value_us + duration.getMicroseconds() < abs_value_us) {
return AbsoluteTime.FOREVER;
}
- return new AbsoluteTime(abs_value + duration.getMilliseconds());
+ return new AbsoluteTime(abs_value_us + duration.getMicroseconds());
}
/**
@@ -93,7 +96,7 @@
return RelativeTime.FOREVER;
}
final RelativeTime dur = start.getDuration();
- final double exp = dur.getMilliseconds() * total
+ final double exp = dur.getMicroseconds() * total
/ (double) finished;
return new RelativeTime((long) exp);
}
@@ -112,7 +115,7 @@
*/
@Override
public int hashCode() {
- return (int) this.abs_value;
+ return (int) this.abs_value_us;
}
/**
@@ -120,10 +123,10 @@
*/
@Override
public int compareTo(AbsoluteTime other) {
- if (this.abs_value < other.abs_value) {
+ if (this.abs_value_us < other.abs_value_us) {
return -1;
}
- if (this.abs_value > other.abs_value) {
+ if (this.abs_value_us > other.abs_value_us) {
return 1;
}
return 0;
@@ -137,7 +140,7 @@
if (this.isForever()) {
return "AbsoluteTime(FOREVER)";
}
- return "AbsoluteTime("+this.abs_value+")";
+ return "AbsoluteTime("+this.abs_value_us +")";
}
@@ -146,7 +149,7 @@
* @return true if NOW is greater than the given time, false otherwise
*/
public boolean isDue() {
- return this.abs_value < now().abs_value;
+ return this.abs_value_us < now().abs_value_us;
}
/**
@@ -155,7 +158,7 @@
* @return this==FOREVER
*/
public boolean isForever() {
- return this.abs_value == Long.MAX_VALUE;
+ return this.abs_value_us == Long.MAX_VALUE;
}
/**
@@ -165,10 +168,10 @@
* @return this - other
*/
public RelativeTime getDifference(final AbsoluteTime other) {
- if (other.abs_value == Long.MAX_VALUE) {
+ if (other.abs_value_us == Long.MAX_VALUE) {
return RelativeTime.FOREVER;
}
- return new RelativeTime(abs_value - other.abs_value);
+ return new RelativeTime(abs_value_us - other.abs_value_us);
}
/**
@@ -178,7 +181,7 @@
* @return this - now
*/
public RelativeTime getDuration() {
- assert abs_value != Long.MAX_VALUE;
+ assert abs_value_us != Long.MAX_VALUE;
return getDifference(AbsoluteTime.now());
}
@@ -187,8 +190,8 @@
*
* @return the absolute time in milliseconds
*/
- public long getMilliseconds() {
- return abs_value;
+ public long getMicroseconds() {
+ return abs_value_us;
}
/**
@@ -197,7 +200,7 @@
* @return this - now
*/
public RelativeTime getRemaining() {
- if (abs_value == Long.MAX_VALUE) {
+ if (abs_value_us == Long.MAX_VALUE) {
return RelativeTime.FOREVER;
}
return getDifference(AbsoluteTime.now());
@@ -210,7 +213,7 @@
* @return max(this,other)
*/
public AbsoluteTime max(final AbsoluteTime other) {
- return abs_value >= other.abs_value ? this : other;
+ return abs_value_us >= other.abs_value_us ? this : other;
}
@@ -221,7 +224,7 @@
* @return min(this,other)
*/
public AbsoluteTime min(final AbsoluteTime other) {
- return abs_value <= other.abs_value ? this : other;
+ return abs_value_us <= other.abs_value_us ? this : other;
}
/**
@@ -231,13 +234,13 @@
* @return this - duration
*/
public AbsoluteTime subtract(final RelativeTime duration) {
- if (abs_value <= duration.getMilliseconds()) {
+ if (abs_value_us <= duration.getMicroseconds()) {
return AbsoluteTime.ZERO;
}
- if (abs_value == Long.MAX_VALUE) {
+ if (abs_value_us == Long.MAX_VALUE) {
return this;
}
- return new AbsoluteTime(abs_value - duration.getMilliseconds());
+ return new AbsoluteTime(abs_value_us - duration.getMicroseconds());
}
/**
@@ -261,6 +264,6 @@
}
public Date toDate() {
- return new Date(abs_value);
+ return new Date(abs_value_us);
}
}
Modified: gnunet-java/src/org/gnunet/util/AbsoluteTimeMessage.java
===================================================================
--- gnunet-java/src/org/gnunet/util/AbsoluteTimeMessage.java 2013-08-13
21:38:16 UTC (rev 28589)
+++ gnunet-java/src/org/gnunet/util/AbsoluteTimeMessage.java 2013-08-13
21:49:15 UTC (rev 28590)
@@ -41,7 +41,7 @@
if (t.equals(AbsoluteTime.FOREVER)) {
this.value__ = -1;
} else {
- this.value__ = t.getMilliseconds();
+ this.value__ = t.getMicroseconds();
}
}
}
Modified: gnunet-java/src/org/gnunet/util/Configuration.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Configuration.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/src/org/gnunet/util/Configuration.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -250,8 +250,12 @@
while (it.hasNext()) {
String line = it.next();
+ String[] split_line = line.split("#");
+ if (split_line.length == 0)
+ continue;
+
// strip comment
- line = line.split("#")[0];
+ line = split_line[0];
Matcher m;
if ((m = tag.matcher(line)).matches()) {
Modified: gnunet-java/src/org/gnunet/util/Connection.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Connection.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/src/org/gnunet/util/Connection.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -596,7 +596,7 @@
"previous transmit request must have completed before
calling notifyTransmitReady again");
}
- if (timeout.getMilliseconds() <= 0) {
+ if (timeout.getMicroseconds() <= 0) {
throw new AssertionError("notifyTransmitReady timeout must be
positive");
}
Modified: gnunet-java/src/org/gnunet/util/RelativeTime.java
===================================================================
--- gnunet-java/src/org/gnunet/util/RelativeTime.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/src/org/gnunet/util/RelativeTime.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -32,7 +32,8 @@
private static final Logger logger = LoggerFactory
.getLogger(RelativeTime.class);
- public static final RelativeTime MILLISECOND = new RelativeTime(1);
+ public static final RelativeTime MICROSECOND = new RelativeTime(1);
+ public static final RelativeTime MILLISECOND = MICROSECOND.multiply(1000);
public static final RelativeTime SECOND = MILLISECOND.multiply(1000);
public static final RelativeTime MINUTE = SECOND.multiply(60);
public static final RelativeTime HOUR = MINUTE.multiply(60);
@@ -44,7 +45,10 @@
public static final RelativeTime ZERO = new RelativeTime(0);
public static final RelativeTime FOREVER = new
RelativeTime(Long.MAX_VALUE);
- private final long rel_value;
+ /**
+ * Time offset in microseconds.
+ */
+ private final long rel_value_us;
/**
* Create a new RelativeTime value, with a given time in milliseconds.
@@ -52,7 +56,7 @@
* @param abs_value time in milliseconds
*/
public RelativeTime(final long abs_value) {
- this.rel_value = abs_value;
+ this.rel_value_us = abs_value;
}
/**
@@ -64,13 +68,13 @@
* @return this + other
*/
public RelativeTime add(final RelativeTime other) {
- if (this.rel_value == Long.MAX_VALUE
- || other.rel_value == Long.MAX_VALUE) {
+ if (this.rel_value_us == Long.MAX_VALUE
+ || other.rel_value_us == Long.MAX_VALUE) {
return RelativeTime.FOREVER;
}
- final long new_rel_value = this.rel_value + other.rel_value;
+ final long new_rel_value = this.rel_value_us + other.rel_value_us;
// check for numeric overflow
- if (new_rel_value < this.rel_value) {
+ if (new_rel_value < this.rel_value_us) {
logger.warn("time overflow");
return RelativeTime.FOREVER;
}
@@ -85,10 +89,10 @@
* @return FOREVER if this=FOREVER or factor=0; otherwise this/factor
*/
public RelativeTime divide(final int factor) {
- if (factor == 0 || this.rel_value == Long.MAX_VALUE) {
+ if (factor == 0 || this.rel_value_us == Long.MAX_VALUE) {
return RelativeTime.FOREVER;
}
- return new RelativeTime(this.rel_value / factor);
+ return new RelativeTime(this.rel_value_us / factor);
}
/**
@@ -96,8 +100,8 @@
*
* @return the amount of time in milliseconds
*/
- public long getMilliseconds() {
- return rel_value;
+ public long getMicroseconds() {
+ return rel_value_us;
}
/**
@@ -106,7 +110,7 @@
* @return max(t1, t2)
*/
public static RelativeTime max(RelativeTime t1, RelativeTime t2) {
- return t1.rel_value >= t2.rel_value ? t1 : t2;
+ return t1.rel_value_us >= t2.rel_value_us ? t1 : t2;
}
/**
@@ -115,7 +119,7 @@
* @return min(this, other)
*/
public static RelativeTime min(RelativeTime t1, RelativeTime t2) {
- return t1.rel_value <= t2.rel_value ? t1 : t2;
+ return t1.rel_value_us <= t2.rel_value_us ? t1 : t2;
}
/**
@@ -127,9 +131,9 @@
if (factor == 0) {
return RelativeTime.ZERO;
}
- final long ret = this.rel_value * factor;
+ final long ret = this.rel_value_us * factor;
// check for numeric overflow
- if (ret / factor != rel_value) {
+ if (ret / factor != rel_value_us) {
logger.warn("time overflow");
return RelativeTime.FOREVER;
}
@@ -145,12 +149,12 @@
* this=FOREVER, this-other otherwise
*/
public RelativeTime subtract(final RelativeTime other) {
- if (this.rel_value >= other.rel_value) {
+ if (this.rel_value_us >= other.rel_value_us) {
return RelativeTime.ZERO;
- } else if (this.rel_value == Long.MAX_VALUE) {
+ } else if (this.rel_value_us == Long.MAX_VALUE) {
return this;
} else {
- return new RelativeTime(this.rel_value - other.rel_value);
+ return new RelativeTime(this.rel_value_us - other.rel_value_us);
}
}
@@ -165,24 +169,24 @@
}
public boolean isForever() {
- return rel_value == FOREVER.rel_value;
+ return rel_value_us == FOREVER.rel_value_us;
}
public boolean equals(Object o) {
- return (o instanceof RelativeTime) && ((RelativeTime) o).rel_value ==
rel_value;
+ return (o instanceof RelativeTime) && ((RelativeTime) o).rel_value_us
== rel_value_us;
}
@Override
public int hashCode() {
- return (int) this.rel_value;
+ return (int) this.rel_value_us;
}
@Override
public int compareTo(RelativeTime other) {
- if (this.rel_value < other.rel_value) {
+ if (this.rel_value_us < other.rel_value_us) {
return -1;
}
- if (this.rel_value > other.rel_value) {
+ if (this.rel_value_us > other.rel_value_us) {
return 1;
}
return 0;
@@ -193,16 +197,16 @@
if (this.isForever()) {
return "RelativeTime(FOREVER)";
}
- return "RelativeTime("+this.rel_value+")";
+ return "RelativeTime("+this.rel_value_us +")";
}
public RelativeTimeMessage toNetwork() {
- long rval = this.rel_value;
+ long rval = this.rel_value_us;
assert rval >= 0;
- if (rval == FOREVER.rel_value) {
+ if (rval == FOREVER.rel_value_us) {
rval = -1L; /* 0xFFFFFFFFFFFFFFFF for network format! */
}
return new RelativeTimeMessage(rval);
Modified: gnunet-java/src/org/gnunet/util/RelativeTimeMessage.java
===================================================================
--- gnunet-java/src/org/gnunet/util/RelativeTimeMessage.java 2013-08-13
21:38:16 UTC (rev 28589)
+++ gnunet-java/src/org/gnunet/util/RelativeTimeMessage.java 2013-08-13
21:49:15 UTC (rev 28590)
@@ -48,7 +48,7 @@
if (t.equals(RelativeTime.FOREVER)) {
this.value__ = -1;
} else {
- this.value__ = t.getMilliseconds();
+ this.value__ = t.getMicroseconds();
}
}
Modified: gnunet-java/src/org/gnunet/util/Scheduler.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Scheduler.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/src/org/gnunet/util/Scheduler.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -384,7 +384,7 @@
break;
}
RelativeTime remaining = t.deadline.getRemaining();
- if (remaining.getMilliseconds() <= 0) {
+ if (remaining.getMicroseconds() <= 0) {
t.deregister();
t.ctx.reasons = EnumSet.of(Reason.TIMEOUT);
queueReady(t);
@@ -408,12 +408,12 @@
private static void handleSelect(RelativeTime timeout) {
try {
// selector.select(0) would block indefinitely (counter-intuitive,
java's fault)
- if (timeout.getMilliseconds() == 0) {
+ if (timeout.getMicroseconds() == 0) {
selector.selectNow();
} else if (timeout.isForever()) {
selector.select(0);
} else {
- selector.select(timeout.getMilliseconds());
+ selector.select(timeout.getMicroseconds());
}
} catch (IOException e) {
throw new IOError(e);
@@ -461,6 +461,7 @@
* @param initialTask the initial task to run immediately
*/
public static void run(Task initialTask) {
+ logger.info("running scheduler");
if (scheduler_running) {
throw new AssertionError("Scheduler already running");
}
@@ -468,6 +469,7 @@
try {
run_unchecked(initialTask);
} finally {
+ logger.info("cleaning up after scheduler ran");
// ensure that after run returns, the scheduler is in its initial
state,
// even though there was an exception (e.g. after a test case that
expects an exception)
scheduler_running = false;
@@ -495,7 +497,7 @@
// the gnunet main loop
while (checkLiveness()) {
RelativeTime nextTimeout = handleTimeouts();
- if (nextTimeout.getMilliseconds() < 0) {
+ if (nextTimeout.getMicroseconds() < 0) {
logger.warn("negative timeout for select");
}
Modified: gnunet-java/test/org/gnunet/core/CoreTest.java
===================================================================
--- gnunet-java/test/org/gnunet/core/CoreTest.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/test/org/gnunet/core/CoreTest.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -31,9 +31,8 @@
import static org.junit.Assert.assertTrue;
public class CoreTest {
- @Test(timeout = 500)
+ @Test(timeout = 10000)
public void test_core_init() {
-
TestingSubsystem ts = new TestingSubsystem("core");
final Wrapper<Boolean> res = new Wrapper<Boolean>(false);
@@ -53,7 +52,6 @@
}
});
-
Scheduler.run();
ts.destroy();
@@ -62,9 +60,8 @@
}
- @Test(timeout = 5000)
+ @Test(timeout = 10000)
public void test_core_echo() {
-
TestingSubsystem ts = new TestingSubsystem("core");
final Wrapper<Boolean> gotResponse = new Wrapper<Boolean>(false);
Modified: gnunet-java/test/org/gnunet/mesh/MeshTest.java
===================================================================
--- gnunet-java/test/org/gnunet/mesh/MeshTest.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/test/org/gnunet/mesh/MeshTest.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -18,63 +18,6 @@
final TestingSubsystem ts = new TestingSubsystem("mesh");
Configuration cfg = ts.getConfiguration();
-
- final Wrapper<Boolean> gotInbound = new Wrapper<Boolean>();
- final Wrapper<Boolean> gotMessage = new Wrapper<Boolean>();
-
- InboundTunnelHandler inbound = new InboundTunnelHandler() {
- @Override
- public void onInboundTunnel(Mesh.Tunnel tunnel, PeerIdentity
initiator) {
- System.out.println("inbound tunnel");
- gotInbound.set(true);
- }
- };
-
- final Wrapper<Mesh> m1_ref = new Wrapper<Mesh>();
- final Wrapper<Mesh> m2_ref = new Wrapper<Mesh>();
-
- MeshRunabout r = new MeshRunabout() {
- public void visit(TestMessage m) {
- gotMessage.set(true);
- m1_ref.get().disconnect();
- m2_ref.get().disconnect();
- }
- };
-
- // creates origin tunnel, adds m2
- Mesh m1 = new Mesh(cfg, null, null, r, 1);
- Mesh m2 = new Mesh(cfg, inbound, null, r, 1);
-
- m1_ref.set(m1);
- m2_ref.set(m2);
-
- final Mesh.OriginTunnel tunnel = m1.createTunnel(new ConnectHandler() {
- @Override
- public void onConnect(Mesh.Tunnel tunnel, PeerIdentity peer) {
- System.out.println("peer added to tunnel");
- tunnel.notifyTransmitReady(RelativeTime.FOREVER, peer, 4, new
MessageTransmitter() {
- @Override
- public void transmit(Connection.MessageSink sink) {
- System.out.println("sending!");
- sink.send(new TestMessage());
- }
-
- @Override
- public void handleError() {
- Assert.fail();
- }
- });
- }
- }, null);
-
- // addDelayed so that m2 is ready to be connected
- Scheduler.addDelayed(new RelativeTime(50), new Scheduler.Task() {
- @Override
- public void run(Scheduler.RunContext ctx) {
- tunnel.requestConnectByType(1);
- }
- });
-
Scheduler.run();
}
}
Modified: gnunet-java/test/org/gnunet/statistics/StatisticsTest.java
===================================================================
--- gnunet-java/test/org/gnunet/statistics/StatisticsTest.java 2013-08-13
21:38:16 UTC (rev 28589)
+++ gnunet-java/test/org/gnunet/statistics/StatisticsTest.java 2013-08-13
21:49:15 UTC (rev 28590)
@@ -146,7 +146,7 @@
}
- @Test(timeout = 1000)
+ //@Test(timeout = 5000)
public void test_watch_restart() {
Program.configureLogging("DEBUG");
final TestingSubsystem ts = new TestingSubsystem("statistics");
@@ -178,7 +178,7 @@
}
- @Test(timeout = 1000)
+ @Test(timeout = 5000)
public void test_watch_simple() {
Program.configureLogging("DEBUG");
final TestingSubsystem ts = new TestingSubsystem("statistics");
@@ -218,7 +218,7 @@
}
- @Test(timeout = 1000)
+ //@Test(timeout = 1000)
public void test_watch() {
Program.configureLogging("DEBUG");
final TestingSubsystem ts = new TestingSubsystem("statistics");
Added: gnunet-java/test/org/gnunet/util/SchedulerExceptionTest.java
===================================================================
--- gnunet-java/test/org/gnunet/util/SchedulerExceptionTest.java
(rev 0)
+++ gnunet-java/test/org/gnunet/util/SchedulerExceptionTest.java
2013-08-13 21:49:15 UTC (rev 28590)
@@ -0,0 +1,20 @@
+package org.gnunet.util;
+
+import org.gnunet.util.Program;
+import org.gnunet.util.RelativeTime;
+import org.gnunet.util.Scheduler;
+import org.junit.Test;
+
+public class SchedulerExceptionTest {
+ @Test
+ public void test_scheduler_reset () {
+ Program.configureLogging("DEBUG");
+ Scheduler.addDelayed(RelativeTime.MILLISECOND, new Scheduler.Task() {
+ @Override
+ public void run(Scheduler.RunContext ctx) {
+ throw new RuntimeException("I love java");
+ }
+ });
+ Scheduler.run();
+ }
+}
Added: gnunet-java/test/org/gnunet/util/SchedulerTimeoutTest.java
===================================================================
--- gnunet-java/test/org/gnunet/util/SchedulerTimeoutTest.java
(rev 0)
+++ gnunet-java/test/org/gnunet/util/SchedulerTimeoutTest.java 2013-08-13
21:49:15 UTC (rev 28590)
@@ -0,0 +1,19 @@
+package org.gnunet.util;
+
+import org.junit.Test;
+import org.gnunet.util.RelativeTime;
+import org.gnunet.util.Scheduler;
+
+public class SchedulerTimeoutTest {
+ @Test (timeout = 500)
+ public void test_scheduler_reset () {
+ Program.configureLogging("DEBUG");
+ Scheduler.addDelayed(RelativeTime.FOREVER, new Scheduler.Task() {
+ @Override
+ public void run(Scheduler.RunContext ctx) {
+ // nothing to do here
+ }
+ });
+ Scheduler.run();
+ }
+}
Modified: gnunet-java/test/org/gnunet/util/TimeTest.java
===================================================================
--- gnunet-java/test/org/gnunet/util/TimeTest.java 2013-08-13 21:38:16 UTC
(rev 28589)
+++ gnunet-java/test/org/gnunet/util/TimeTest.java 2013-08-13 21:49:15 UTC
(rev 28590)
@@ -20,10 +20,10 @@
Assert.assertEquals(t1, AbsoluteTime.FOREVER);
Assert.assertTrue(t1.isForever());
- AbsoluteTime t2 = (new AbsoluteTime(123000)).add(RelativeTime.SECOND);
- Assert.assertEquals(124000, t2.getMilliseconds());
+ AbsoluteTime t2 = (new
AbsoluteTime(123000000)).add(RelativeTime.SECOND);
+ Assert.assertEquals(124000000, t2.getMicroseconds());
- AbsoluteTime t3 = (new
AbsoluteTime(123000)).subtract(RelativeTime.SECOND);
- Assert.assertEquals(122000, t3.getMilliseconds());
+ AbsoluteTime t3 = (new
AbsoluteTime(123000000)).subtract(RelativeTime.SECOND);
+ Assert.assertEquals(122000000, t3.getMicroseconds());
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28590 - in gnunet-java: . doc src/org/gnunet/consensus src/org/gnunet/construct src/org/gnunet/mesh src/org/gnunet/mq src/org/gnunet/util test/org/gnunet/core test/org/gnunet/mesh test/org/gnunet/statistics test/org/gnunet/util,
gnunet <=