1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package com .alipay .sofa .rpc .registry .zk .base ;
18
+
19
+ import com .alipay .sofa .rpc .context .RpcInternalContext ;
20
+ import com .alipay .sofa .rpc .context .RpcInvokeContext ;
21
+ import com .alipay .sofa .rpc .context .RpcRunningState ;
22
+ import com .alipay .sofa .rpc .context .RpcRuntimeContext ;
23
+ import org .apache .curator .test .TestingServer ;
24
+ import org .junit .AfterClass ;
25
+ import org .junit .BeforeClass ;
26
+
27
+ import java .io .IOException ;
28
+
29
+ /**
30
+ * @author bystander
31
+ * if you use zk to be registry ,your test case must be extends this class
32
+ * @version $Id: BaseZkTest.java, v 0.1 2018年05月22日 7:55 PM bystander Exp $
33
+ */
34
+ public abstract class BaseZkTest {
35
+ protected static TestingServer server = null ;
36
+
37
+ @ BeforeClass
38
+ public static void adBeforeClass () {
39
+ RpcRunningState .setUnitTestMode (true );
40
+
41
+ try {
42
+ server = new TestingServer (2181 , true );
43
+ server .start ();
44
+ } catch (Exception e ) {
45
+ e .printStackTrace ();
46
+ }
47
+ }
48
+
49
+ @ AfterClass
50
+ public static void adAfterClass () {
51
+ RpcRuntimeContext .destroy ();
52
+ RpcInternalContext .removeContext ();
53
+ RpcInvokeContext .removeContext ();
54
+
55
+ if (server != null ) {
56
+ try {
57
+ server .stop ();
58
+ } catch (IOException e ) {
59
+ e .printStackTrace ();
60
+ }
61
+ }
62
+ }
63
+ }
0 commit comments