-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
SparkShimsTest.java
151 lines (133 loc) · 5.42 KB
/
SparkShimsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.zeppelin.spark;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Properties;
import org.apache.hadoop.util.VersionInfo;
import org.apache.zeppelin.interpreter.BaseZeppelinContext;
import org.apache.zeppelin.interpreter.remote.RemoteEventClientWrapper;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(Enclosed.class)
public class SparkShimsTest {
@RunWith(Parameterized.class)
public static class ParamTests {
@Parameters(name = "Hadoop {0} supports jobUrl: {1}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[][] {
{"2.6.0", false},
{"2.6.1", false},
{"2.6.2", false},
{"2.6.3", false},
{"2.6.4", false},
{"2.6.5", false},
{"2.6.6", true}, // The latest fixed version
{"2.6.7", true}, // Future version
{"2.7.0", false},
{"2.7.1", false},
{"2.7.2", false},
{"2.7.3", false},
{"2.7.4", true}, // The latest fixed version
{"2.7.5", true}, // Future versions
{"2.8.0", false},
{"2.8.1", false},
{"2.8.2", true}, // The latest fixed version
{"2.8.3", true}, // Future versions
{"2.9.0", true}, // The latest fixed version
{"2.9.1", true}, // Future versions
{"3.0.0", true}, // The latest fixed version
{"3.0.0-alpha4", true}, // The latest fixed version
{"3.0.1", true}, // Future versions
});
}
@Parameter public String version;
@Parameter(1)
public boolean expected;
@Test
public void checkYarnVersionTest() {
SparkShims sparkShims =
new SparkShims() {
@Override
public void setupSparkListener(String master, String sparkWebUrl) {}
};
assertEquals(expected, sparkShims.supportYarn6615(version));
}
}
@RunWith(PowerMockRunner.class)
@PrepareForTest({BaseZeppelinContext.class, VersionInfo.class})
@PowerMockIgnore({"javax.net.*", "javax.security.*"})
public static class SingleTests {
@Mock Properties mockProperties;
@Captor ArgumentCaptor<Map<String, String>> argumentCaptor;
SparkShims sparkShims;
@Before
public void setUp() {
PowerMockito.mockStatic(BaseZeppelinContext.class);
RemoteEventClientWrapper mockRemoteEventClientWrapper = mock(RemoteEventClientWrapper.class);
when(BaseZeppelinContext.getEventClient()).thenReturn(mockRemoteEventClientWrapper);
doNothing()
.when(mockRemoteEventClientWrapper)
.onParaInfosReceived(anyString(), anyString(), argumentCaptor.capture());
when(mockProperties.getProperty("spark.jobGroup.id")).thenReturn("job-note-paragraph");
try {
sparkShims = SparkShims.getInstance(SparkVersion.SPARK_2_0_0.toString());
} catch (Throwable ignore) {
sparkShims = SparkShims.getInstance(SparkVersion.SPARK_1_6_0.toString());
}
}
@Test
public void runUnerLocalTest() {
sparkShims.buildSparkJobUrl("local", "http://sparkurl", 0, mockProperties);
Map<String, String> mapValue = argumentCaptor.getValue();
assertTrue(mapValue.keySet().contains("jobUrl"));
assertTrue(mapValue.get("jobUrl").contains("/jobs/job?id="));
}
@Test
public void runUnerYarnTest() {
sparkShims.buildSparkJobUrl("yarn", "http://sparkurl", 0, mockProperties);
Map<String, String> mapValue = argumentCaptor.getValue();
assertTrue(mapValue.keySet().contains("jobUrl"));
if (sparkShims.supportYarn6615(VersionInfo.getVersion())) {
assertTrue(mapValue.get("jobUrl").contains("/jobs/job?id="));
} else {
assertFalse(mapValue.get("jobUrl").contains("/jobs/job?id="));
}
}
}
}