1+ package com .apache .dubbo .sample ;
2+
3+ import org .junit .Test ;
4+ import junit .framework .TestCase ;
5+ import static org .junit .Assert .*;
6+
7+ import org .apache .dubbo .common .constants .CommonConstants ;
8+ import org .apache .dubbo .config .ApplicationConfig ;
9+ import org .apache .dubbo .config .ReferenceConfig ;
10+ import org .apache .dubbo .config .RegistryConfig ;
11+ import org .apache .dubbo .sample .hello .Helloworld ;
12+
13+ import java .io .IOException ;
14+ import java .util .concurrent .TimeUnit ;
15+
16+ import com .apache .dubbo .sample .basic .*;
17+
18+ public class TestHelloWorld {
19+
20+ @ Test
21+ public void testHelloWorld () throws Exception {
22+ ReferenceConfig <IGreeter > ref = new ReferenceConfig <>();
23+ ref .setInterface (IGreeter .class );
24+ ref .setCheck (false );
25+ ref .setProtocol (CommonConstants .TRIPLE );
26+ ref .setLazy (true );
27+ ref .setTimeout (100000 );
28+ ref .setApplication (new ApplicationConfig ("demo-consumer" ));
29+ ref .setRegistry (new RegistryConfig ("zookeeper://127.0.0.1:2181" ));
30+ final IGreeter iGreeter = ref .get ();
31+
32+ System .out .println ("dubbo ref started" );
33+ Helloworld .HelloRequest req = Helloworld .HelloRequest .newBuilder ().setName ("laurence" ).build ();
34+ try {
35+ final Helloworld .User reply = iGreeter .sayHello (req );
36+ TimeUnit .SECONDS .sleep (1 );
37+ System .out .println ("Reply:" + reply );
38+ TestCase .assertEquals (reply .getName (), "Hello laurence" );
39+ TestCase .assertEquals (reply .getId (), "12345" );
40+ TestCase .assertEquals (reply .getAge (), 21 );
41+ } catch (Throwable t ) {
42+ t .printStackTrace ();
43+ System .exit (1 );
44+ }
45+ }
46+ }
0 commit comments