aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2012-01-04 10:51:06 +0000
committerFlorian Dold <florian.dold@gmail.com>2012-01-04 10:51:06 +0000
commit0216f984559a9e16ff6fd87da7de61085f80408f (patch)
treeebd8272f04899c13c1c1e58d65d0e136ec687df2 /test
parent20cbc0f996beb942bd62580f681ff01ff8729b91 (diff)
downloadgnunet-java-0216f984559a9e16ff6fd87da7de61085f80408f.tar.gz
gnunet-java-0216f984559a9e16ff6fd87da7de61085f80408f.zip
NSE client almost working
Diffstat (limited to 'test')
-rw-r--r--test/org/gnunet/construct/ConstructTest.java25
-rw-r--r--test/org/gnunet/construct/QueryMessage.java14
-rw-r--r--test/org/gnunet/construct/SimpleTestMessage.java17
-rw-r--r--test/org/gnunet/construct/SimpleTestMessage2.java9
-rw-r--r--test/org/gnunet/construct/SizeTestMessage.java15
-rw-r--r--test/org/gnunet/construct/StringMessage.java12
-rw-r--r--test/org/gnunet/construct/VarTestMessage.java9
-rw-r--r--test/org/gnunet/services/ConfigUtil.java52
-rw-r--r--test/org/gnunet/services/NetworkSizeEstimationServiceTest.java37
-rw-r--r--test/org/gnunet/services/StatisticsServiceTest.java38
-rw-r--r--test/org/gnunet/services/nse.conf24
-rw-r--r--test/org/gnunet/services/statistics.conf0
12 files changed, 236 insertions, 16 deletions
diff --git a/test/org/gnunet/construct/ConstructTest.java b/test/org/gnunet/construct/ConstructTest.java
index 5c4c741..f9055ec 100644
--- a/test/org/gnunet/construct/ConstructTest.java
+++ b/test/org/gnunet/construct/ConstructTest.java
@@ -1,17 +1,10 @@
1package org.gnunet.construct; 1package org.gnunet.construct;
2 2
3import java.math.BigInteger;
4
5import org.gnunet.messages.MessageHeader;
6import org.gnunet.messages.QueryMessage;
7import org.gnunet.messages.SimpleTestMessage;
8import org.gnunet.messages.SimpleTestMessage2;
9import org.gnunet.messages.SizeTestMessage;
10import org.gnunet.messages.StringMessage;
11import org.gnunet.messages.VarTestMessage;
12import org.junit.Assert; 3import org.junit.Assert;
13import org.junit.Test; 4import org.junit.Test;
14 5
6import java.math.BigInteger;
7
15public class ConstructTest { 8public class ConstructTest {
16 9
17 10
@@ -94,7 +87,7 @@ public class ConstructTest {
94 public void test_QueryMessage() { 87 public void test_QueryMessage() {
95 QueryMessage qm = new QueryMessage(); 88 QueryMessage qm = new QueryMessage();
96 qm.header = new MessageHeader(); 89 qm.header = new MessageHeader();
97 qm.header.type = 0x42; 90 qm.header.messageType = 0x42;
98 qm.query = 0x43; 91 qm.query = 0x43;
99 qm.varsize = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 92 qm.varsize = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
100 14, 15 }; 93 14, 15 };
@@ -105,8 +98,8 @@ public class ConstructTest {
105 98
106 QueryMessage qm2 = Construct.parseAs(a, 0, QueryMessage.class); 99 QueryMessage qm2 = Construct.parseAs(a, 0, QueryMessage.class);
107 100
108 Assert.assertEquals(qm.header.size, qm2.header.size); 101 Assert.assertEquals(qm.header.messageSize, qm2.header.messageSize);
109 Assert.assertEquals(qm.header.type, qm2.header.type); 102 Assert.assertEquals(qm.header.messageType, qm2.header.messageType);
110 Assert.assertEquals(qm.query, qm2.query); 103 Assert.assertEquals(qm.query, qm2.query);
111 104
112 Assert.assertArrayEquals(qm.varsize, qm2.varsize); 105 Assert.assertArrayEquals(qm.varsize, qm2.varsize);
@@ -135,8 +128,8 @@ public class ConstructTest {
135 public void test_MessageHeader() { 128 public void test_MessageHeader() {
136 MessageHeader h1 = new MessageHeader(); 129 MessageHeader h1 = new MessageHeader();
137 130
138 h1.size = 42; 131 h1.messageSize = 42;
139 h1.type = 52; 132 h1.messageType = 52;
140 133
141 byte[] a = Construct.toBinary(h1); 134 byte[] a = Construct.toBinary(h1);
142 135
@@ -146,7 +139,7 @@ public class ConstructTest {
146 139
147 Assert.assertArrayEquals(a, b); 140 Assert.assertArrayEquals(a, b);
148 141
149 Assert.assertEquals(h1.size, h2.size); 142 Assert.assertEquals(h1.messageSize, h2.messageSize);
150 Assert.assertEquals(h1.type, h2.type); 143 Assert.assertEquals(h1.messageType, h2.messageType);
151 } 144 }
152} 145}
diff --git a/test/org/gnunet/construct/QueryMessage.java b/test/org/gnunet/construct/QueryMessage.java
new file mode 100644
index 0000000..d337c51
--- /dev/null
+++ b/test/org/gnunet/construct/QueryMessage.java
@@ -0,0 +1,14 @@
1package org.gnunet.construct;
2
3@MessageId(0x123)
4public class QueryMessage implements Message {
5
6 @Nested
7 public MessageHeader header;
8
9 @UInt8
10 public int query;
11
12 @ByteFill
13 public byte[] varsize;
14}
diff --git a/test/org/gnunet/construct/SimpleTestMessage.java b/test/org/gnunet/construct/SimpleTestMessage.java
new file mode 100644
index 0000000..0460151
--- /dev/null
+++ b/test/org/gnunet/construct/SimpleTestMessage.java
@@ -0,0 +1,17 @@
1package org.gnunet.construct;
2
3@MessageId(3210)
4public class SimpleTestMessage implements Message {
5
6 @UInt8
7 public short v1;
8
9 @UInt8
10 public short v2;
11
12 @Nested
13 public SimpleTestMessage2 mn;
14
15 @FixedSizeArray(length=5)
16 public SimpleTestMessage2[] mns;
17}
diff --git a/test/org/gnunet/construct/SimpleTestMessage2.java b/test/org/gnunet/construct/SimpleTestMessage2.java
new file mode 100644
index 0000000..0fa4f66
--- /dev/null
+++ b/test/org/gnunet/construct/SimpleTestMessage2.java
@@ -0,0 +1,9 @@
1package org.gnunet.construct;
2
3//@MessageId(321)
4public class SimpleTestMessage2 implements Message {
5
6 @UInt32
7 public long value;
8
9}
diff --git a/test/org/gnunet/construct/SizeTestMessage.java b/test/org/gnunet/construct/SizeTestMessage.java
new file mode 100644
index 0000000..b4ef79e
--- /dev/null
+++ b/test/org/gnunet/construct/SizeTestMessage.java
@@ -0,0 +1,15 @@
1package org.gnunet.construct;
2
3@MessageId(987)
4public class SizeTestMessage implements Message {
5
6 @FrameSize
7 @UInt16
8 public long totalSize;
9
10 @UInt16
11 public long someValue;
12
13 @ByteFill
14 public byte[] rest;
15}
diff --git a/test/org/gnunet/construct/StringMessage.java b/test/org/gnunet/construct/StringMessage.java
new file mode 100644
index 0000000..bb9f399
--- /dev/null
+++ b/test/org/gnunet/construct/StringMessage.java
@@ -0,0 +1,12 @@
1package org.gnunet.construct;
2
3public class StringMessage implements Message {
4 @UInt8
5 public int num;
6
7 @ZeroTerminatedString
8 public String str;
9
10 @UInt8
11 public int num2;
12}
diff --git a/test/org/gnunet/construct/VarTestMessage.java b/test/org/gnunet/construct/VarTestMessage.java
new file mode 100644
index 0000000..a0c2de7
--- /dev/null
+++ b/test/org/gnunet/construct/VarTestMessage.java
@@ -0,0 +1,9 @@
1package org.gnunet.construct;
2
3public class VarTestMessage implements Message {
4 @UInt16
5 public long length;
6
7 @VariableSizeArray(lengthField="length")
8 public SimpleTestMessage2[] msgs;
9}
diff --git a/test/org/gnunet/services/ConfigUtil.java b/test/org/gnunet/services/ConfigUtil.java
new file mode 100644
index 0000000..0a92d9a
--- /dev/null
+++ b/test/org/gnunet/services/ConfigUtil.java
@@ -0,0 +1,52 @@
1package org.gnunet.services;
2
3import java.io.*;
4import java.net.URL;
5
6/**
7 * Created by IntelliJ IDEA.
8 * User: dold
9 * Date: 1/3/12
10 * Time: 12:17 AM
11 * To change this template use File | Settings | File Templates.
12 */
13public class ConfigUtil {
14 static File copyConfigResource(String resName) {
15 URL res = StatisticsServiceTest.class.getResource("nse.conf");
16
17 File tmpFile;
18
19 try {
20 tmpFile = File.createTempFile("cfg", null);
21 } catch (IOException e) {
22 throw new IOError(e);
23 }
24
25 FileOutputStream tmpFileStream;
26 try {
27 tmpFileStream = new FileOutputStream(tmpFile);
28 } catch (FileNotFoundException e) {
29 throw new RuntimeException("temp file deleted externally");
30 }
31
32
33 InputStream resStream;
34 try {
35 resStream = res.openStream();
36 } catch (IOException e) {
37 throw new IOError(e);
38 }
39
40 int b;
41 try {
42 while ((b=resStream.read()) != -1) {
43 tmpFileStream.write(b);
44 }
45 tmpFileStream.close();
46 } catch (IOException e) {
47 throw new IOError(e);
48 }
49
50 return tmpFile;
51 }
52}
diff --git a/test/org/gnunet/services/NetworkSizeEstimationServiceTest.java b/test/org/gnunet/services/NetworkSizeEstimationServiceTest.java
new file mode 100644
index 0000000..acd4cd6
--- /dev/null
+++ b/test/org/gnunet/services/NetworkSizeEstimationServiceTest.java
@@ -0,0 +1,37 @@
1package org.gnunet.services;
2
3
4import org.gnunet.service.NetworkSizeEstimationService;
5import org.gnunet.util.Configuration;
6import org.gnunet.util.Scheduler;
7import org.junit.Test;
8
9import java.io.File;
10
11public class NetworkSizeEstimationServiceTest {
12 @Test
13 public void test_1() {
14
15 File tmpFile = ConfigUtil.copyConfigResource("nse.conf");
16
17 /*
18 Process p;
19 try {
20 String[] cmd = {"gnunet-service-statistics", "-c", tmpFile.getAbsolutePath()};
21 p = Runtime.getRuntime().exec(cmd);
22 } catch (IOException e) {
23 throw new IOError(e);
24 }
25 */
26
27 Configuration cfg = new Configuration(tmpFile.getAbsolutePath());
28
29 NetworkSizeEstimationService svc = new NetworkSizeEstimationService(cfg);
30
31 System.out.println("starting scheduler");
32
33 Scheduler.run(Scheduler.NO_TASK);
34
35 // p.destroy();
36 }
37}
diff --git a/test/org/gnunet/services/StatisticsServiceTest.java b/test/org/gnunet/services/StatisticsServiceTest.java
new file mode 100644
index 0000000..86d177f
--- /dev/null
+++ b/test/org/gnunet/services/StatisticsServiceTest.java
@@ -0,0 +1,38 @@
1package org.gnunet.services;
2
3
4import org.gnunet.service.StatisticsService;
5import org.gnunet.util.Configuration;
6import org.junit.Test;
7
8import java.io.File;
9import java.io.IOError;
10import java.io.IOException;
11
12public class StatisticsServiceTest {
13
14
15
16 @Test
17 public void test_1() {
18
19
20 File tmpFile = ConfigUtil.copyConfigResource("statistics.conf");
21
22 Process p;
23 try {
24 String[] cmd = {"gnunet-service-statistics", "-c", tmpFile.getAbsolutePath()};
25 p = Runtime.getRuntime().exec(cmd);
26 } catch (IOException e) {
27 throw new IOError(e);
28 }
29
30 Configuration cfg = new Configuration(tmpFile.getAbsolutePath());
31
32
33
34 StatisticsService s = new StatisticsService(cfg);
35
36 p.destroy();
37 }
38}
diff --git a/test/org/gnunet/services/nse.conf b/test/org/gnunet/services/nse.conf
new file mode 100644
index 0000000..da0c18a
--- /dev/null
+++ b/test/org/gnunet/services/nse.conf
@@ -0,0 +1,24 @@
1[nse]
2AUTOSTART = YES
3PORT = 2097
4HOSTNAME = localhost
5HOME = $SERVICEHOME
6CONFIG = $DEFAULTCONFIG
7BINARY = gnunet-service-nse
8ACCEPT_FROM = 127.0.0.1;
9ACCEPT_FROM6 = ::1;
10# UNIXPATH = /tmp/test-nse-service-nse.unix
11# UNIX_MATCH_UID = YES
12# UNIX_MATCH_GID = YES
13PROOFFILE = $SERVICEHOME/.nse-proof
14HISTOGRAM = $SERVICEHOME/nse-history.log
15
16# How 'slowly' should the proof-of-work be constructed (delay
17# between rounds); sane values between 0 and ~1000.
18WORKDELAY = 5 ms
19
20# Note: changing any of the values below will make this peer
21# completely incompatible with other peers!
22INTERVAL = 1 h
23# 26 is about 10 minutes on a modern i7 (single-core)
24WORKBITS = 26 \ No newline at end of file
diff --git a/test/org/gnunet/services/statistics.conf b/test/org/gnunet/services/statistics.conf
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/org/gnunet/services/statistics.conf