diff options
Diffstat (limited to 'src/test/java/org/gnunet/util/ResolverTest.java')
-rw-r--r-- | src/test/java/org/gnunet/util/ResolverTest.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/test/java/org/gnunet/util/ResolverTest.java b/src/test/java/org/gnunet/util/ResolverTest.java new file mode 100644 index 0000000..ae56b79 --- /dev/null +++ b/src/test/java/org/gnunet/util/ResolverTest.java | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | package org.gnunet.util; | ||
22 | |||
23 | import org.gnunet.testing.TestingSetup; | ||
24 | import org.gnunet.testing.TestingSubsystem; | ||
25 | import org.junit.Assert; | ||
26 | import org.junit.Test; | ||
27 | import org.slf4j.Logger; | ||
28 | import org.slf4j.LoggerFactory; | ||
29 | |||
30 | import java.net.InetAddress; | ||
31 | |||
32 | import static org.junit.Assert.assertTrue; | ||
33 | import static org.junit.Assert.fail; | ||
34 | |||
35 | /** | ||
36 | * @author Florian Dold | ||
37 | */ | ||
38 | public class ResolverTest { | ||
39 | private static final Logger logger = LoggerFactory | ||
40 | .getLogger(ResolverTest.class); | ||
41 | @Test | ||
42 | public void test_resolver() { | ||
43 | final Wrapper<Boolean> finished1 = new Wrapper<Boolean>(true); | ||
44 | final Wrapper<Boolean> finished2 = new Wrapper<Boolean>(true); | ||
45 | |||
46 | TestingSubsystem ts = new TestingSubsystem("resolver"); | ||
47 | |||
48 | |||
49 | Resolver r = Resolver.getInstance(); | ||
50 | r.setConfiguration(ts.getConfiguration()); | ||
51 | |||
52 | r.resolveHostname("gnunet.org", RelativeTime.FOREVER, new Resolver.AddressCallback() { | ||
53 | @Override | ||
54 | public void onAddress(InetAddress addr) { | ||
55 | logger.info("Hostname resolved to " + addr.getHostAddress()); | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | public void onFinished() { | ||
60 | finished1.set(true); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | public void onTimeout() { | ||
65 | fail(); | ||
66 | } | ||
67 | }); | ||
68 | r.resolveHostname("gnu.org", RelativeTime.FOREVER, new Resolver.AddressCallback() { | ||
69 | @Override | ||
70 | public void onAddress(InetAddress addr) { | ||
71 | logger.info("Hostname resolved to " + addr.getHostAddress()); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public void onFinished() { | ||
76 | finished2.set(true); | ||
77 | } | ||
78 | |||
79 | @Override | ||
80 | public void onTimeout() { | ||
81 | fail(); | ||
82 | } | ||
83 | }); | ||
84 | |||
85 | Scheduler.run(); | ||
86 | |||
87 | assertTrue(finished1.get()); | ||
88 | |||
89 | assertTrue(finished2.get()); | ||
90 | } | ||
91 | } | ||
92 | |||