1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.comm;
20
21 import org.apache.giraph.comm.netty.NettyClient;
22 import org.apache.giraph.comm.netty.NettyServer;
23 import org.apache.giraph.comm.netty.handler.SaslServerHandler;
24 import org.apache.giraph.comm.netty.handler.WorkerRequestServerHandler;
25 import org.apache.giraph.conf.GiraphConfiguration;
26 import org.apache.giraph.conf.GiraphConstants;
27 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
28 import org.apache.giraph.utils.IntNoOpComputation;
29 import org.apache.giraph.utils.MockUtils;
30 import org.apache.giraph.worker.WorkerInfo;
31 import org.apache.hadoop.io.IntWritable;
32 import org.apache.hadoop.mapreduce.Mapper.Context;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.mockito.Mockito;
36
37 import com.google.common.collect.Lists;
38
39 import java.io.IOException;
40
41 import static org.mockito.Mockito.mock;
42 import static org.mockito.Mockito.when;
43
44
45
46
47 public class SaslConnectionTest {
48
49 private ImmutableClassesGiraphConfiguration conf;
50
51 @Before
52 public void setUp() {
53 GiraphConfiguration tmpConfig = new GiraphConfiguration();
54 tmpConfig.setComputationClass(IntNoOpComputation.class);
55 GiraphConstants.AUTHENTICATE.set(tmpConfig, true);
56 conf = new ImmutableClassesGiraphConfiguration(tmpConfig);
57 }
58
59
60
61
62
63
64 @Test
65 public void connectSingleClientServer() throws IOException {
66 @SuppressWarnings("rawtypes")
67 Context context = mock(Context.class);
68 when(context.getConfiguration()).thenReturn(conf);
69
70 ServerData<IntWritable, IntWritable, IntWritable> serverData =
71 MockUtils.createNewServerData(conf, context);
72
73 SaslServerHandler.Factory mockedSaslServerFactory =
74 Mockito.mock(SaslServerHandler.Factory.class);
75
76 SaslServerHandler mockedSaslServerHandler =
77 Mockito.mock(SaslServerHandler.class);
78 when(mockedSaslServerFactory.newHandler(conf)).
79 thenReturn(mockedSaslServerHandler);
80
81 WorkerInfo workerInfo = new WorkerInfo();
82 workerInfo.setTaskId(-1);
83 NettyServer server =
84 new NettyServer(conf,
85 new WorkerRequestServerHandler.Factory(serverData),
86 workerInfo,
87 context,
88 mockedSaslServerFactory,
89 new MockExceptionHandler());
90 server.start();
91 workerInfo.setInetSocketAddress(server.getMyAddress(), server.getLocalHostOrIp());
92
93 NettyClient client = new NettyClient(context, conf, new WorkerInfo(),
94 new MockExceptionHandler());
95 server.setFlowControl(client.getFlowControl());
96 client.connectAllAddresses(Lists.<WorkerInfo>newArrayList(workerInfo));
97
98 client.stop();
99 server.stop();
100 }
101 }