code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
@Override protected void handleGet(final HttpServletRequest req, final HttpServletResponse resp, final Session session) throws ServletException, IOException { if (hasParam(req, ConnectorParams.ACTION_PARAM)) { handleAJAXAction(req, resp, session); } else { handleStatePageLoad(req, resp, session); } }
User facing servlet for Azkaban default metric display
handleGet
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
Apache-2.0
private void handleAJAXAction(final HttpServletRequest req, final HttpServletResponse resp, final Session session) throws ServletException, IOException { final HashMap<String, Object> ret = new HashMap<>(); final int executorId = getIntParam(req, ConnectorParams.EXECUTOR_ID_PARAM); final String actionName = getParam(req, ConnectorParams.ACTION_PARAM); if (actionName.equals(ConnectorParams.STATS_GET_METRICHISTORY)) { handleGetMetricHistory(executorId, req, ret, session.getUser()); } else if (actionName.equals(ConnectorParams.STATS_GET_ALLMETRICSNAME)) { handleGetAllMetricName(executorId, req, ret); } else if (actionName.equals(ConnectorParams.STATS_SET_REPORTINGINTERVAL)) { handleChangeConfigurationRequest(executorId, ConnectorParams.STATS_SET_REPORTINGINTERVAL, req, ret); } else if (actionName.equals(ConnectorParams.STATS_SET_CLEANINGINTERVAL)) { handleChangeConfigurationRequest(executorId, ConnectorParams.STATS_SET_CLEANINGINTERVAL, req, ret); } else if (actionName.equals(ConnectorParams.STATS_SET_MAXREPORTERPOINTS)) { handleChangeConfigurationRequest(executorId, ConnectorParams.STATS_SET_MAXREPORTERPOINTS, req, ret); } else if (actionName.equals(ConnectorParams.STATS_SET_ENABLEMETRICS)) { handleChangeConfigurationRequest(executorId, ConnectorParams.STATS_SET_ENABLEMETRICS, req, ret); } else if (actionName.equals(ConnectorParams.STATS_SET_DISABLEMETRICS)) { handleChangeConfigurationRequest(executorId, ConnectorParams.STATS_SET_DISABLEMETRICS, req, ret); } writeJSON(resp, ret); }
User facing servlet for Azkaban default metric display
handleAJAXAction
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
Apache-2.0
private void handleGetAllMetricName(final int executorId, final HttpServletRequest req, final HashMap<String, Object> ret) throws IOException { final Map<String, Object> result; try { result = this.execManagerAdapter.callExecutorStats(executorId, ConnectorParams.STATS_GET_ALLMETRICSNAME, (Pair<String, String>[]) null); if (result.containsKey(ConnectorParams.RESPONSE_ERROR)) { ret.put("error", result.get(ConnectorParams.RESPONSE_ERROR).toString()); } else { ret.put("metricList", result.get("data")); } } catch (final ExecutorManagerException e) { logger.error(e.getMessage(), e); ret.put("error", "Failed to fetch metric names for executor : " + executorId); } }
Get all metrics tracked by the given executor
handleGetAllMetricName
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
Apache-2.0
private void handleChangeConfigurationRequest(final int executorId, final String actionName, final HttpServletRequest req, final HashMap<String, Object> ret) throws ServletException, IOException { try { final Map<String, Object> result = this.execManagerAdapter.callExecutorStats(executorId, actionName, getAllParams(req)); if (result.containsKey(ConnectorParams.RESPONSE_ERROR)) { ret.put(ConnectorParams.RESPONSE_ERROR, result.get(ConnectorParams.RESPONSE_ERROR).toString()); } else { ret.put(ConnectorParams.STATUS_PARAM, result.get(ConnectorParams.STATUS_PARAM)); } } catch (final ExecutorManagerException ex) { logger.error(ex.getMessage(), ex); ret.put("error", "Failed to change config change"); } }
Generic method to facilitate actionName action using Azkaban exec server @param actionName Name of the action
handleChangeConfigurationRequest
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
Apache-2.0
private void handleGetMetricHistory(final int executorId, final HttpServletRequest req, final HashMap<String, Object> ret, final User user) throws IOException, ServletException { try { final Map<String, Object> result = this.execManagerAdapter.callExecutorStats(executorId, ConnectorParams.STATS_GET_METRICHISTORY, getAllParams(req)); if (result.containsKey(ConnectorParams.RESPONSE_ERROR)) { ret.put(ConnectorParams.RESPONSE_ERROR, result.get(ConnectorParams.RESPONSE_ERROR).toString()); } else { ret.put("data", result.get("data")); } } catch (final ExecutorManagerException ex) { logger.error(ex.getMessage(), ex); ret.put("error", "Failed to fetch metric history"); } }
Get metric snapshots for a metric and date specification
handleGetMetricHistory
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
Apache-2.0
private void handleStatePageLoad(final HttpServletRequest req, final HttpServletResponse resp, final Session session) throws ServletException { final Page page = newPage(req, resp, session, "azkaban/webapp/servlet/velocity/statsPage.vm"); try { final Collection<Executor> executors = this.execManagerAdapter.getAllActiveExecutors(); page.add("executorList", executors); if (executors.isEmpty()) { throw new ExecutorManagerException("Executor list is empty."); } final Map<String, Object> result = this.execManagerAdapter.callExecutorStats(executors.iterator().next().getId(), ConnectorParams.STATS_GET_ALLMETRICSNAME, (Pair<String, String>[]) null); if (result.containsKey(ConnectorParams.RESPONSE_ERROR)) { page.add("errorMsg", result.get(ConnectorParams.RESPONSE_ERROR) .toString()); } else { page.add("metricList", result.get("data")); } } catch (final Exception e) { logger.error(e.getMessage(), e); page.add("errorMsg", "Failed to get a response from Azkaban exec server"); } page.render(); }
Get metric snapshots for a metric and date specification
handleStatePageLoad
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
Apache-2.0
@Override protected void handlePost(final HttpServletRequest req, final HttpServletResponse resp, final Session session) throws ServletException, IOException { }
Get metric snapshots for a metric and date specification
handlePost
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatsServlet.java
Apache-2.0
public static String getRealClientIpAddr(final Map<String, String> httpHeaders, final String remoteAddr) { // If some upstream device added an X-Forwarded-For header // use it for the client ip // This will support scenarios where load balancers or gateways // front the Azkaban web server and a changing Ip address invalidates the session String clientIp = httpHeaders.getOrDefault(X_FORWARDED_FOR_HEADER, null); if (clientIp == null) { clientIp = remoteAddr; } else { // header can contain comma separated list of upstream servers - get the first one final String[] ips = clientIp.split(","); clientIp = ips[0]; } // Strip off port and only get IP address // todo: this is broken for IPv6, where e.g. a "loopback" address looks like "0:0:0:0:0:0:0:1" final String[] parts = clientIp.split(":"); clientIp = parts[0]; return clientIp; }
Gets the actual client IP address on a best effort basis as user could be sitting behind a VPN. Get the IP by inspecting the X-Forwarded-For HTTP header or using the provided 'remote IP address' from the low level TCP connection from the client. If multiple IP addresses are provided in the X-Forwarded-For header then the first one (first hop) is used @param httpHeaders List of HTTP headers for the current request @param remoteAddr The client IP address and port from the current request's TCP connection @return The actual client IP address
getRealClientIpAddr
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/WebUtils.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/WebUtils.java
Apache-2.0
public static String getRealClientIpAddr(final HttpServletRequest req) { // If some upstream device added an X-Forwarded-For header // use it for the client ip // This will support scenarios where load balancers or gateways // front the Azkaban web server and a changing Ip address invalidates // the session final HashMap<String, String> headers = new HashMap<>(); headers.put(WebUtils.X_FORWARDED_FOR_HEADER, req.getHeader(WebUtils.X_FORWARDED_FOR_HEADER.toLowerCase())); return WebUtils.getRealClientIpAddr(headers, req.getRemoteAddr()); }
Gets the actual client IP address on a best effort basis as user could be sitting behind a VPN. Get the IP by inspecting the X-Forwarded-For HTTP header or using the provided 'remote IP address' from the low level TCP connection from the client. If multiple IP addresses are provided in the X-Forwarded-For header then the first one (first hop) is used @param req HttpServletRequest @return The actual client IP address
getRealClientIpAddr
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/WebUtils.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/WebUtils.java
Apache-2.0
public static void reportLoginEvent(final EventType eventType, final String username, final String ip, final boolean isSuccess, final String message) { if (azkabanEventReporter != null) { final Map<String, String> metadata = new HashMap<>(); metadata.put("azkabanHost", AzkabanWebServer.getAzkabanProperties().getString(AZKABAN_SERVER_HOST_NAME, hostName)); metadata.put("sessionUser", Strings.isNullOrEmpty(username) ? "unknown" : username); metadata.put("sessionIP", ip); metadata.put("reason", message); metadata.put("appOutcome", isSuccess ? "SUCCESS" : "FAILURE"); azkabanEventReporter.report(eventType, metadata); } }
Report login/logout events via {@link AzkabanEventReporter}, if configured. @param eventType login or logout @param username if known @param ip address of originating host @param isSuccess AKA outcome @param message AKA reason
reportLoginEvent
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/WebUtils.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/WebUtils.java
Apache-2.0
public static void reportLoginEvent(final EventType eventType, final String username, final String ip) { reportLoginEvent(eventType, username, ip, true, null); }
Report login/logout events via {@link AzkabanEventReporter}, if configured. @param eventType login or logout @param username if known @param ip address of originating host @param isSuccess AKA outcome @param message AKA reason
reportLoginEvent
java
azkaban/azkaban
azkaban-web-server/src/main/java/azkaban/webapp/servlet/WebUtils.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/main/java/azkaban/webapp/servlet/WebUtils.java
Apache-2.0
public static void assertStringEqualFileContent(final String expectedFilePath, final String actual) throws IOException { final String expected = new String(Files.readAllBytes(Paths.get(expectedFilePath)), StandardCharsets.UTF_8); assertThat(actual).isEqualToIgnoringWhitespace(expected); }
Assert the given string equals the given file's content. The white space differences are ignored. @param expectedFilePath the expected file path @param actual the actual string @throws IOException the io exception
assertStringEqualFileContent
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/fixture/FileAssertion.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/fixture/FileAssertion.java
Apache-2.0
public static String surroundWithHtmlTag(final String content) { return "<html>\n" + content + "</html>\n"; }
Return the html based content surrounded with the HTML tag. This is useful to compare a fragment of HTML content with a proper expected HTML file so that the expected file can be viewed more easily with a browser. @param content the content @return string
surroundWithHtmlTag
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/fixture/FileAssertion.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/fixture/FileAssertion.java
Apache-2.0
public static Project getMockProject() { final Project project = new Project(1, "test_project"); project.setDescription("My project description"); project.setLastModifiedUser("last_modified_user_name"); project.setUploadLock(true); project.addFeatureFlags(FeatureFlag.ENABLE_PROJECT_ADHOC_UPLOAD, false); final DateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss"); try { final Date modifiedDate = dateFormat.parse("2000:01:02:3:4:5"); final long modifiedTime = modifiedDate.getTime(); project.setLastModifiedTimestamp(modifiedTime); final Date createDate = dateFormat.parse("1999:06:07:8:9:10"); final long createTime = createDate.getTime(); project.setCreateTimestamp(createTime); } catch (final ParseException e) { e.printStackTrace(); } return project; }
Get mock project project. @return a mock project for testing
getMockProject
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/fixture/MockProject.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/fixture/MockProject.java
Apache-2.0
public static VelocityContext getInstance() { final VelocityContext context = new VelocityContext(); context.put("esc", new EscapeTool()); context.put("TimeUtils", TimeUtils.class); return context; }
Gets an instance of the velocity context Add the utility instances that are commonly used in many templates. @return the instance
getInstance
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/fixture/VelocityContextTestUtil.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/fixture/VelocityContextTestUtil.java
Apache-2.0
public static String renderTemplate(final String templateName, final VelocityContext context) { final StringWriter stringWriter = new StringWriter(); final VelocityEngine engine = new VelocityEngine(); engine.init("src/test/resources/velocity.properties"); engine.mergeTemplate(TEMPLATE_BASE_DIR + templateName + ".vm", "UTF-8", context, stringWriter); return stringWriter.getBuffer().toString(); }
Render a template and return the result @param templateName the template name only without the .vm extension @param context the context @return string
renderTemplate
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/fixture/VelocityTemplateTestUtil.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/fixture/VelocityTemplateTestUtil.java
Apache-2.0
public static boolean ignoreCaseContains(final String source, final String target) { final String sourceNoSpace = source.replaceAll("\\s+", ""); final String targetNoSpace = target.replaceAll("\\s+", ""); return sourceNoSpace.contains(targetNoSpace); }
@param source the rendered template as a String @param target the String fragment within the template @return - boolean
ignoreCaseContains
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/fixture/VelocityTemplateTestUtil.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/fixture/VelocityTemplateTestUtil.java
Apache-2.0
public static void assertStringEqualFileContent(final String expectedFileName, final String actual) throws IOException { final String expectedFilePath = EXPECTED_FILE_DIR + expectedFileName; FileAssertion.assertStringEqualFileContent(expectedFilePath, actual); }
Assert the string equals file content in this project's expected file directory. @param expectedFileName the expected file name @param actual the actual @throws IOException the io exception
assertStringEqualFileContent
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/fixture/WebFileAssertion.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/fixture/WebFileAssertion.java
Apache-2.0
@Override public DependencyInstanceContext run(final DependencyInstanceConfig config, final DependencyInstanceRuntimeProps runtimeProps, final DependencyInstanceCallback callback) { return new FakeDependencyInstanceContext1(config, runtimeProps, callback); }
todo chengren311: test-dependency-plugin.jar in resource folder is generated from @see azkaban.flowtrigger.testplugin.FakeDependencyCheck1 @see azkaban.flowtrigger.testplugin.FakeDependencyCheck2 @see azkaban.flowtrigger.testplugin.FakeDependencyInstanceContext1 @see azkaban.flowtrigger.testplugin.FakeDependencyInstanceContext2 But we need to find out a way to auto generate this jar while building.
run
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/flowtrigger/testplugin/FakeDependencyCheck1.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/flowtrigger/testplugin/FakeDependencyCheck1.java
Apache-2.0
@Override public void shutdown() { }
todo chengren311: test-dependency-plugin.jar in resource folder is generated from @see azkaban.flowtrigger.testplugin.FakeDependencyCheck1 @see azkaban.flowtrigger.testplugin.FakeDependencyCheck2 @see azkaban.flowtrigger.testplugin.FakeDependencyInstanceContext1 @see azkaban.flowtrigger.testplugin.FakeDependencyInstanceContext2 But we need to find out a way to auto generate this jar while building.
shutdown
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/flowtrigger/testplugin/FakeDependencyCheck1.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/flowtrigger/testplugin/FakeDependencyCheck1.java
Apache-2.0
@Override public String toString() { return this.config.toString(); }
todo chengren311: test-dependency-plugin.jar in resource folder is generated from @see azkaban.flowtrigger.testplugin.FakeDependencyCheck1 @see azkaban.flowtrigger.testplugin.FakeDependencyCheck2 @see azkaban.flowtrigger.testplugin.FakeDependencyInstanceContext1 @see azkaban.flowtrigger.testplugin.FakeDependencyInstanceContext2 But we need to find out a way to auto generate this jar while building.
toString
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/flowtrigger/testplugin/FakeDependencyCheck1.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/flowtrigger/testplugin/FakeDependencyCheck1.java
Apache-2.0
@Override public void init(final DependencyPluginConfig config) { this.config = config; }
todo chengren311: test-dependency-plugin.jar in resource folder is generated from @see azkaban.flowtrigger.testplugin.FakeDependencyCheck1 @see azkaban.flowtrigger.testplugin.FakeDependencyCheck2 @see azkaban.flowtrigger.testplugin.FakeDependencyInstanceContext1 @see azkaban.flowtrigger.testplugin.FakeDependencyInstanceContext2 But we need to find out a way to auto generate this jar while building.
init
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/flowtrigger/testplugin/FakeDependencyCheck1.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/flowtrigger/testplugin/FakeDependencyCheck1.java
Apache-2.0
public void testValidVersionInternal(final String version) { final ImageVersionDTO dto = new ImageVersionDTO(); dto.setName("testImageType"); List<String> validationErrors = new ArrayList<>(); dto.setVersion(version); boolean result = ValidatorUtils.validateObject(dto, validationErrors, BaseDTO.ValidationOnCreate.class); Assert.assertTrue(result); Assert.assertTrue(validationErrors.isEmpty()); }
Common code for valid versions @param version the image version
testValidVersionInternal
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
Apache-2.0
public void testInvalidVersionInternal(final String version) { final ImageVersionDTO dto = new ImageVersionDTO(); dto.setName("testImageType"); List<String> validationErrors = new ArrayList<>(); dto.setVersion(version); boolean result = ValidatorUtils.validateObject(dto, validationErrors, BaseDTO.ValidationOnCreate.class); Assert.assertFalse(result); Assert.assertFalse(validationErrors.isEmpty()); Assert.assertEquals(1, validationErrors.size()); final String err = "ImageVersion must be in major.minor.patch.hotfix format (ex. 0.1, 1.2, 1.2.5, 1.2.3.4 etc.)."; Assert.assertEquals(err, validationErrors.get(0)); }
Common code for invalid image versions @param version the image version
testInvalidVersionInternal
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
Apache-2.0
@Test public void testValidMajorVersion() { testValidVersionInternal("1"); }
Common code for invalid image versions @param version the image version
testValidMajorVersion
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
Apache-2.0
@Test public void testValidMinorVersion() { testValidVersionInternal("1.2"); }
Common code for invalid image versions @param version the image version
testValidMinorVersion
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
Apache-2.0
@Test public void testValidPatchVersion() { testValidVersionInternal("1.2.3"); }
Common code for invalid image versions @param version the image version
testValidPatchVersion
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
Apache-2.0
@Test public void testValidHotfixVersion() { testValidVersionInternal("1.2.3.4"); }
Common code for invalid image versions @param version the image version
testValidHotfixVersion
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
Apache-2.0
@Test public void testInvalidVersions() { // Valid looking version but have more than 4 values. eg, 1.2.3.4.5 testInvalidVersionInternal("1.2.3.4.5"); // Invalid format of version testInvalidVersionInternal("1.2."); }
Common code for invalid image versions @param version the image version
testInvalidVersions
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/imagemgmt/dto/ImageVersionDTOTest.java
Apache-2.0
@Test public void testWarnedDeploy() { final ProjectManagerResource resource = new ProjectManagerResource(); final Map<String, ValidationReport> reports = new LinkedHashMap<>(); for (int i = 0; i < 3; i++) { addMockWarning(reports, "Test warn level info message."); } // We expect that no exceptions are thrown given a // report with warnings. Anything thrown will result in failure resource.checkReports(reports); }
Test response to deploy with either warn or error reports. If a report has any errors, a RestLiServiceException should be thrown. Warnings should not elicit an exception. If an exception does get raised, it should carry an HTTP 400 status
testWarnedDeploy
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
Apache-2.0
@Test public void testErrorDeploy() { final ProjectManagerResource resource = new ProjectManagerResource(); final Map<String, ValidationReport> reports = new LinkedHashMap<>(); for (int i = 0; i < 3; i++) { addMockError(reports, "Test error level info message."); } // We expect that a RestLiServiceException is thrown given a // report with errors. Uncaught exceptions will result in failure try { resource.checkReports(reports); Assert.fail(); } catch (final RestLiServiceException e) { //Ensure we have the right status code and exit assertEquals(e.getStatus(), HttpStatus.S_400_BAD_REQUEST); } }
Test response to deploy with either warn or error reports. If a report has any errors, a RestLiServiceException should be thrown. Warnings should not elicit an exception. If an exception does get raised, it should carry an HTTP 400 status
testErrorDeploy
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
Apache-2.0
@Test public void testWarnErrorDeploy() { final ProjectManagerResource resource = new ProjectManagerResource(); final Map<String, ValidationReport> reports = new LinkedHashMap<>(); for (int i = 0; i < 7; i++) { // If i is even, make an error report, otherwise make a warning report if (i % 2 == 0) { addMockError(reports, "Test error level info message."); } else { addMockWarning(reports, "Test warn level info message."); } } // We expect that a RestLiServiceException is thrown given a // report with errors. Uncaught exceptions will result in failure try { resource.checkReports(reports); Assert.fail(); } catch (final RestLiServiceException e) { //Ensure we have the right status code and exit assertEquals(e.getStatus(), HttpStatus.S_400_BAD_REQUEST); } }
Test response to deploy with either warn or error reports. If a report has any errors, a RestLiServiceException should be thrown. Warnings should not elicit an exception. If an exception does get raised, it should carry an HTTP 400 status
testWarnErrorDeploy
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
Apache-2.0
@Test public void testErrorMessageDeploy() { final ProjectManagerResource resource = new ProjectManagerResource(); final Map<String, ValidationReport> reports = new LinkedHashMap<>(); addMockError(reports, "This should show up."); // We expect that a RestLiServiceException is thrown given a // report with errors. Uncaught exceptions will result in failure try { resource.checkReports(reports); Assert.fail(); } catch (final RestLiServiceException e) { //Ensure we have the right status code and exit assertEquals(e.getStatus(), HttpStatus.S_400_BAD_REQUEST); assertEquals(e.getMessage(), "Validator Error reports errors: This should show up." + System.getProperty("line.separator")); } }
Test that an error message is attached to the exception on an error
testErrorMessageDeploy
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
Apache-2.0
private void addMockWarning(final Map<String, ValidationReport> reports, final String msg) { final Set<String> warnMsgs = new HashSet<>(); final ValidationReport warnRpt = new ValidationReport(); warnMsgs.add(msg); warnRpt.addWarningMsgs(warnMsgs); reports.put("Warn", warnRpt); }
Test that an error message is attached to the exception on an error
addMockWarning
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
Apache-2.0
private void addMockError(final Map<String, ValidationReport> reports, final String msg) { final Set<String> errorMsgs = new HashSet<>(); final ValidationReport errorRpt = new ValidationReport(); errorMsgs.add(msg); errorRpt.addErrorMsgs(errorMsgs); reports.put("Error", errorRpt); }
Test that an error message is attached to the exception on an error
addMockError
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/restli/DeployProjectTest.java
Apache-2.0
@BeforeClass public static void setUpQuartz() throws Exception { dbOperator = AzDBTestUtility.initQuartzDB(); final String quartzPropsPath = new File("../azkaban-web-server/src/test/resources/quartz.test.properties") .getCanonicalPath(); final Props props = new Props(null, quartzPropsPath); props.put(ConfigurationKeys.ENABLE_QUARTZ, "true"); props.put("database.type", "h2"); props.put("h2.path", "./h2"); final Injector injector = Guice.createInjector( new AzkabanCommonModule(props), new AzkabanWebServerModule(props) ); SERVICE_PROVIDER.unsetInjector(); SERVICE_PROVIDER.setInjector(injector); scheduler = new QuartzScheduler(props); scheduler.start(); }
Use H2-in-mem database to directly test Quartz.
setUpQuartz
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@AfterClass public static void destroyQuartz() { try { scheduler.shutdown(); dbOperator.update("DROP ALL OBJECTS"); dbOperator.update("SHUTDOWN"); } catch (final Exception e) { e.printStackTrace(); } }
Use H2-in-mem database to directly test Quartz.
destroyQuartz
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@Before public void init() { SampleQuartzJob.COUNT_EXECUTION = 0; }
Use H2-in-mem database to directly test Quartz.
init
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@After public void cleanup() throws SchedulerException { scheduler.cleanup(); }
Use H2-in-mem database to directly test Quartz.
cleanup
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@Test public void testCreateScheduleAndRun() throws Exception { scheduler.scheduleJobIfAbsent("* * * * * ?", createJobDescription()); assertThat(scheduler.ifJobExist("SampleJob", "SampleService")).isEqualTo(true); TestUtils.await().untilAsserted(() -> assertThat(SampleQuartzJob.COUNT_EXECUTION) .isNotNull().isGreaterThan(1)); }
Use H2-in-mem database to directly test Quartz.
testCreateScheduleAndRun
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@Test public void testSchedulingDuplicateJob() throws Exception { scheduler.scheduleJobIfAbsent("* * * * * ?", createJobDescription()); assertThat(scheduler.scheduleJobIfAbsent("0 5 * * * ?", createJobDescription())).isFalse(); }
Use H2-in-mem database to directly test Quartz.
testSchedulingDuplicateJob
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@Test public void testInvalidCron() { assertThatThrownBy( () -> scheduler.scheduleJobIfAbsent("0 5 * * * *", createJobDescription())) .isInstanceOf(SchedulerException.class) .hasMessageContaining("The cron expression string"); }
Use H2-in-mem database to directly test Quartz.
testInvalidCron
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@Test public void testUnschedule() throws Exception { scheduler.scheduleJobIfAbsent("* * * * * ?", createJobDescription()); assertThat(scheduler.ifJobExist("SampleJob", "SampleService")).isEqualTo(true); assertThat(scheduler.unscheduleJob("SampleJob", "SampleService")).isTrue(); assertThat(scheduler.ifJobExist("SampleJob", "SampleService")).isEqualTo(false); assertThat(scheduler.unscheduleJob("SampleJob", "SampleService")).isFalse(); }
Use H2-in-mem database to directly test Quartz.
testUnschedule
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@Test public void testPauseSchedule() throws Exception { assertThat(scheduler.pauseJobIfPresent("SampleJob", "SampleService")).isFalse(); scheduler.scheduleJobIfAbsent("* * * * * ?", createJobDescription()); assertThat(scheduler.pauseJobIfPresent("SampleJob", "SampleService")).isTrue(); assertThat(scheduler.isJobPaused("SampleJob", "SampleService")).isEqualTo(true); assertThat(scheduler.resumeJobIfPresent("SampleJob", "SampleService")).isTrue(); assertThat(scheduler.isJobPaused("SampleJob", "SampleService")).isEqualTo(false); // test pausing a paused job scheduler.pauseJobIfPresent("SampleJob", "SampleService"); scheduler.pauseJobIfPresent("SampleJob", "SampleService"); assertThat(scheduler.isJobPaused("SampleJob", "SampleService")).isEqualTo(true); // test resuming a non-paused job scheduler.resumeJobIfPresent("SampleJob", "SampleService"); scheduler.resumeJobIfPresent("SampleJob", "SampleService"); assertThat(scheduler.isJobPaused("SampleJob", "SampleService")).isEqualTo(false); }
Use H2-in-mem database to directly test Quartz.
testPauseSchedule
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
private QuartzJobDescription createJobDescription() { return new QuartzJobDescription<>(SampleQuartzJob.class, "SampleJob", "SampleService"); }
Use H2-in-mem database to directly test Quartz.
createJobDescription
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/scheduler/QuartzSchedulerTest.java
Apache-2.0
@Test public void testExternalAnalyzerButton() throws Exception { final VelocityContext context = VelocityContextTestUtil.getInstance(); ExternalLink externalLink1 = new ExternalLink( "topic1", "Label1", "http://topic1.linkedin.com/", true); context.put("externalAnalyzers", Arrays.asList(externalLink1)); String result = VelocityTemplateTestUtil.renderTemplate("executingflowpage", context); assertTrue(VelocityTemplateTestUtil. ignoreCaseContains(result, EXTERNAL_ANALYZER_ELEMENT1)); ExternalLink externalLink2 = new ExternalLink( "topic2", "Label2", "http://topic2.linkedin.com/", false); context.put("externalAnalyzers", Arrays.asList(externalLink1, externalLink2)); result = VelocityTemplateTestUtil.renderTemplate("executingflowpage", context); assertTrue(VelocityTemplateTestUtil. ignoreCaseContains(result, EXTERNAL_ANALYZER_ELEMENT1)); assertTrue(VelocityTemplateTestUtil. ignoreCaseContains(result, EXTERNAL_ANALYZER_ELEMENT2)); }
Test aims to check that the external analyzer button is displayed in the page. @throws Exception the exception
testExternalAnalyzerButton
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutionFlowViewTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutionFlowViewTest.java
Apache-2.0
@Test public void postAjaxExecuteFlowWithInvalidSlaSettings() throws Exception { mockTestProjectAndFlow(); mockSubmitExecution(); this.req.addParameter("ajax", "executeFlow"); this.req.addParameter("project", "testProject"); this.req.addParameter("flow", "testFlow"); this.req.addParameter("slaSettings[1]", "broken-syntax-for-sla"); this.executorServlet.handlePost(this.req, this.res, this.session); assertEquals(200, this.res.getStatus()); assertEquals("Error parsing flow options: Error parsing SLA setting 'broken-syntax-for-sla': " + "java.lang.ArrayIndexOutOfBoundsException: 1", this.res.getResponseJson().path("error").asText()); }
When SLA options can't be parsed, API is expected to return 200 OK with JSON that has "error".
postAjaxExecuteFlowWithInvalidSlaSettings
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
Apache-2.0
@Test public void postAjaxExecuteFlowWithMissingProjectParameter() throws Exception { this.req.addParameter("ajax", "executeFlow"); try { this.executorServlet.handlePost(this.req, this.res, this.session); fail("Expected exception was not thrown"); } catch (final ServletException e) { assertEquals("Missing required parameter 'project'.", e.getMessage()); } }
When executeFlow is called without project param, API is expected to raise an exception.
postAjaxExecuteFlowWithMissingProjectParameter
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
Apache-2.0
@Test public void postAjaxFlowInfoErrorFetching() throws Exception { this.req.addParameter("ajax", "flowInfo"); this.req.addParameter("execid", "123"); this.executorServlet.handlePost(this.req, this.res, this.session); assertEquals(200, this.res.getStatus()); assertEquals("Cannot find execution '123'", this.res.getResponseJson().path("error").asText()); }
When execution is not found, API is expected to return 200 OK with JSON that has "error".
postAjaxFlowInfoErrorFetching
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
Apache-2.0
@Test public void testPostAjaxUpdateContainerProperty() throws Exception { ContainerizedDispatchManager containerizedDispatchManager = new ContainerizedDispatchManager( new Props(), null, null, null, null, null, null, null, null, null, new DummyEventListener(), new DummyContainerizationMetricsImpl(), null); Mockito.when(this.azkabanWebServer.getExecutorManager()) .thenReturn(containerizedDispatchManager); this.executorServlet.init(this.servletConfig); this.req.addParameter("ajax", "updateProp"); this.req.addParameter("propType", "containerDispatch"); this.req.addParameter("subType", "updateAllowList"); this.req.addParameter("val", "spark,java"); this.executorServlet.handlePost(this.req, this.res, this.session); Set<String> output = containerizedDispatchManager.getContainerJobTypeCriteria().getAllowList(); assertEquals(ImmutableSet.of("java", "spark"), output); this.req.removeParameter("subType"); this.req.removeParameter("val"); this.req.addParameter("subType", "appendAllowList"); this.req.addParameter("val", "noop"); this.executorServlet.handlePost(this.req, this.res, this.session); output = containerizedDispatchManager.getContainerJobTypeCriteria().getAllowList(); assertEquals(ImmutableSet.of("java", "spark", "noop"), output); this.req.removeParameter("subType"); this.req.removeParameter("val"); this.req.addParameter("subType", "removeFromAllowList"); this.req.addParameter("val", "spark"); this.executorServlet.handlePost(this.req, this.res, this.session); output = containerizedDispatchManager.getContainerJobTypeCriteria().getAllowList(); assertEquals(ImmutableSet.of("java", "noop"), output); this.req.removeParameter("subType"); this.req.removeParameter("val"); this.req.addParameter("subType", "updateRampUp"); this.req.addParameter("val", "7"); this.executorServlet.handlePost(this.req, this.res, this.session); assertEquals(7, containerizedDispatchManager.getContainerRampUpCriteria().getRampUp()); // test append proxy.to.user deny list this.req.removeParameter("subType"); this.req.removeParameter("val"); this.req.addParameter("subType", "appendDenyList"); this.req.addParameter("val","azktest,azkdata,azdev"); this.executorServlet.handlePost(this.req, this.res, this.session); output = containerizedDispatchManager.getContainerProxyUserCriteria().getDenyList(); assertEquals(ImmutableSet.of("azktest", "azkdata","azdev"), output); //test remove proxy.to.user deny list this.req.removeParameter("subType"); this.req.removeParameter("val"); this.req.addParameter("subType", "removeFromDenyList"); this.req.addParameter("val","azkdev,azkdata,azktest"); this.executorServlet.handlePost(this.req, this.res, this.session); output = containerizedDispatchManager.getContainerProxyUserCriteria().getDenyList(); assertEquals(ImmutableSet.of("azdev"), output); }
When execution is not found, API is expected to return 200 OK with JSON that has "error".
testPostAjaxUpdateContainerProperty
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
Apache-2.0
@Test public void testPostAjaxUpdateGeneralProperty() throws Exception { AbstractExecutorManagerAdapter abstractExecutorManagerAdapter = mock(AbstractExecutorManagerAdapter.class); Mockito.doCallRealMethod().when(abstractExecutorManagerAdapter).enableOfflineLogsLoader(anyBoolean()); Mockito.doCallRealMethod().when(abstractExecutorManagerAdapter).isOfflineLogsLoaderEnabled(); Mockito.when(this.azkabanWebServer.getExecutorManager()) .thenReturn(abstractExecutorManagerAdapter); this.executorServlet.init(this.servletConfig); this.req.addParameter("ajax", "updateProp"); this.req.addParameter("propType", "general"); this.req.removeParameter("subType"); this.req.removeParameter("val"); this.req.addParameter("subType", "enableOfflineLogsLoader"); this.req.addParameter("val","true"); this.executorServlet.handlePost(this.req, this.res, this.session); assertTrue(abstractExecutorManagerAdapter.isOfflineLogsLoaderEnabled()); this.req.removeParameter("subType"); this.req.removeParameter("val"); this.req.addParameter("subType", "enableOfflineLogsLoader"); this.req.addParameter("val","false"); this.executorServlet.handlePost(this.req, this.res, this.session); assertFalse(abstractExecutorManagerAdapter.isOfflineLogsLoaderEnabled()); }
When execution is not found, API is expected to return 200 OK with JSON that has "error".
testPostAjaxUpdateGeneralProperty
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
Apache-2.0
@Test public void testPostAjaxUpdateContainerizedImplProperty() throws Exception { AtomicInteger vpaRampup = new AtomicInteger(0); AtomicBoolean vpaEnabled = new AtomicBoolean(true); ContainerizedImpl containerizedImpl = mock(ContainerizedImpl.class); Mockito.when(containerizedImpl.getVPARampUp()).thenReturn(vpaRampup.get()); Mockito.when(containerizedImpl.getVPAEnabled()).thenReturn(vpaEnabled.get()); doAnswer(invocation -> { vpaRampup.set(invocation.getArgument(0)); return null; }).when(containerizedImpl).setVPARampUp(anyInt()); doAnswer(invocation -> { vpaEnabled.set(invocation.getArgument(0)); return null; }).when(containerizedImpl).setVPAEnabled(anyBoolean()); ContainerizedDispatchManager containerizedDispatchManager = new ContainerizedDispatchManager( new Props(), null, null, null, null, null, null, containerizedImpl, null, null, new DummyEventListener(), new DummyContainerizationMetricsImpl(), null); Mockito.when(this.azkabanWebServer.getExecutorManager()) .thenReturn(containerizedDispatchManager); this.executorServlet.init(this.servletConfig); this.req.addParameter("ajax", "updateProp"); this.req.addParameter("propType", "containerizedImpl"); this.req.addParameter("subType", "updateVPARampUp"); this.req.addParameter("val", "100"); this.executorServlet.handlePost(this.req, this.res, this.session); assertEquals(vpaRampup.get(), 100); this.req.removeParameter("val"); this.req.addParameter("val", "0"); this.executorServlet.handlePost(this.req, this.res, this.session); assertEquals(vpaRampup.get(), 0); this.req.removeParameter("subType"); this.req.addParameter("subType", "updateVPAEnabled"); this.req.addParameter("val", "false"); this.executorServlet.handlePost(this.req, this.res, this.session); assertFalse(vpaEnabled.get()); this.req.removeParameter("val"); this.req.addParameter("val", "true"); this.executorServlet.handlePost(this.req, this.res, this.session); assertTrue(vpaEnabled.get()); }
When execution is not found, API is expected to return 200 OK with JSON that has "error".
testPostAjaxUpdateContainerizedImplProperty
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ExecutorServletTest.java
Apache-2.0
@Test public void testLoginRevealingCredentialsShouldThrowFailure() throws Exception { final String clientIp = "127.0.0.1:10000"; final String sessionId = "111"; final String queryString = "action=login&username=azkaban&password=azkaban"; final String[] mockCredentials = {"azkaban"}; final HashMap<String, String[]> mockParameterMap = new HashMap<String, String[]>() { { put("username", mockCredentials); put("password", mockCredentials); } }; final HttpServletRequest req = MockLoginAzkabanServlet .getRequestWithNoUpstream(clientIp, sessionId, "POST"); when(req.getParameterMap()).thenReturn(mockParameterMap); when(req.getQueryString()).thenReturn(queryString); final StringWriter writer = new StringWriter(); final HttpServletResponse resp = getResponse(writer); final MockLoginAzkabanServlet servlet = MockLoginAzkabanServlet.getServletWithSession(sessionId, "user", "127.0.0.1"); servlet.doPost(req, resp); // Assert that expected error message is returned assertEquals("Login error. Must pass username and password in request body", writer.toString()); }
Simulates users passing username/password via URI where it would be logged by Azkaban Web Server
testLoginRevealingCredentialsShouldThrowFailure
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/LoginAbstractAzkabanServletTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/LoginAbstractAzkabanServletTest.java
Apache-2.0
@Test public void testUploadButtonIsPresent() { final VelocityContext context = VelocityContextTestUtil.getInstance(); context.put("hideUploadProjectButton", false); final String result = VelocityTemplateTestUtil.renderTemplate("projectpageheader", context); assertThat(VelocityTemplateTestUtil.ignoreCaseContains(result, UPLOAD_BUTTON)).isTrue(); }
Test validates the enable/disable feature of the 'Upload' button
testUploadButtonIsPresent
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ProjectPageHeaderTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ProjectPageHeaderTest.java
Apache-2.0
@Test public void testUploadButtonIsNotPresent() { final VelocityContext context = VelocityContextTestUtil.getInstance(); context.put("hideUploadProjectButton", true); final String result = VelocityTemplateTestUtil.renderTemplate("projectpageheader", context); assertThat(VelocityTemplateTestUtil.ignoreCaseContains(result, UPLOAD_BUTTON)).isFalse(); }
Test validates the enable/disable feature of the 'Upload' button
testUploadButtonIsNotPresent
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ProjectPageHeaderTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ProjectPageHeaderTest.java
Apache-2.0
@Test public void testProjectSideBarView() throws Exception { final VelocityContext context = VelocityContextTestUtil.getInstance(); final Project project = MockProject.getMockProject(); // Intentionally tries to inject a Javascript. project.setDescription("<script>window.alert(\"hacked\")</script>"); context.put("projectName", project.getName()); context.put("description", project.getDescription()); context.put("createTimestamp",project.getCreateTimestamp()); context.put("lastModifiedTimestamp",project.getLastModifiedTimestamp()); context.put("lastModifiedUser",project.getLastModifiedUser()); context.put("projectUploadLock", project.isUploadLocked()); context.put("adhocUpload", project.isAdhocUploadEnabled()); context.put("showUploadLockPanel", true); context.put("showAdhocUploadFeature", true); context.put("admins", "admin_name"); context.put("userpermission", "admin_permission"); final String result = VelocityTemplateTestUtil.renderTemplate("projectsidebar", context); final String actual = FileAssertion.surroundWithHtmlTag(result); WebFileAssertion.assertStringEqualFileContent("project-side-bar.html", actual); }
Test project side bar view. The project description should be HTML encoded to avoid cross site scripting issues. @throws Exception the exception
testProjectSideBarView
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/ProjectSideBarViewTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/ProjectSideBarViewTest.java
Apache-2.0
@Test public void testWhenNoXForwardedForHeaderUseClientIp() { final String clientIp = "127.0.0.1:10000"; final Map<String, String> headers = new HashMap<>(); final String ip = WebUtils.getRealClientIpAddr(headers, clientIp); assertEquals(ip, "127.0.0.1"); }
Test class for azkaban.webapp.servlet.WebUtils
testWhenNoXForwardedForHeaderUseClientIp
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
Apache-2.0
@Test public void testWhenClientIpNoPort() { final String clientIp = "192.168.1.1"; final Map<String, String> headers = new HashMap<>(); final String ip = WebUtils.getRealClientIpAddr(headers, clientIp); assertEquals(ip, "192.168.1.1"); }
Test class for azkaban.webapp.servlet.WebUtils
testWhenClientIpNoPort
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
Apache-2.0
@Test public void testWhenXForwardedForHeaderUseHeader() { final String clientIp = "127.0.0.1:10000"; final String upstreamIp = "192.168.1.1:10000"; final Map<String, String> headers = new HashMap<>(); headers.put("X-Forwarded-For", upstreamIp); final String ip = WebUtils.getRealClientIpAddr(headers, clientIp); assertEquals(ip, "192.168.1.1"); }
Test class for azkaban.webapp.servlet.WebUtils
testWhenXForwardedForHeaderUseHeader
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
Apache-2.0
@Test public void testWhenXForwardedForHeaderMultipleUpstreamsUseHeader() { final String clientIp = "127.0.0.1:10000"; final String upstreamIp = "192.168.1.1:10000"; final Map<String, String> headers = new HashMap<>(); headers.put("X-Forwarded-For", upstreamIp + ",127.0.0.1,55.55.55.55"); final String ip = WebUtils.getRealClientIpAddr(headers, clientIp); assertEquals(ip, "192.168.1.1"); }
Test class for azkaban.webapp.servlet.WebUtils
testWhenXForwardedForHeaderMultipleUpstreamsUseHeader
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
Apache-2.0
@Test @Ignore // will fail right now public void testIPv6NoPort() { final String clientIp = "fe80::aede:48ff:.55805"; // or ::1, or fe80::1cc4:170d:463d:99d1%en0, or http://[fe80::1ff:fe23:4567:890a%25eth0]:443/ final Map<String, String> headers = new HashMap<>(); final String ip = WebUtils.getRealClientIpAddr(headers, clientIp); assertEquals(ip, "fe80::aede:48ff"); }
Test class for azkaban.webapp.servlet.WebUtils
testIPv6NoPort
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
Apache-2.0
@Test public void testReportLoginEvent() { // can't really test much without a way to inject a mock of AzkabanEventReporter into // WebUtils, but let's at least invoke it anyway: WebUtils.reportLoginEvent(EventType.USER_LOGIN, "itsme", "127.0.0.1"); }
Test class for azkaban.webapp.servlet.WebUtils
testReportLoginEvent
java
azkaban/azkaban
azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
https://github.com/azkaban/azkaban/blob/master/azkaban-web-server/src/test/java/azkaban/webapp/servlet/WebUtilsTest.java
Apache-2.0
@Before public void setup() throws Exception { // So log4j doesn't complain BasicConfigurator.configure(); this.localCacheFolder = TEMP_DIR.newFolder("dependencies"); this.chttpRootURI = URI.create("chttp://www.example.com:9000/repo/"); this.cacheRootURI = URI.create("file://" + localCacheFolder.getCanonicalPath()); this.chttpAbsoluteJarURI = this.chttpRootURI.resolve(RELATIVE_JAR_PATH); URIBuilder b = new URIBuilder(this.chttpAbsoluteJarURI); b.setScheme("http"); // http://www.example.com:9000/repo/jars/some.jar this.originAbsoluteJarURI = b.build(); this.expectedLocallyCachedJar = new File(this.localCacheFolder, RELATIVE_JAR_PATH); this.cacheFS = mock(FileSystem.class); Configuration conf = new Configuration(false); // Stop FileSystem.get() from returning cached instances of CachedHttpFileSystem, it messes with our tests. // we need to create a new object each time. conf.setBoolean("fs.chttp.impl.disable.cache", true); conf.set("fs.chttp.impl", azkaban.cachedhttpfilesystem.CachedHttpFileSystem.class.getName()); conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName()); conf.set(CachedHttpFileSystem.CACHE_ROOT_URI, this.cacheRootURI.toString()); this.cachedHttpFileSystem = spy((CachedHttpFileSystem) FileSystem.get(chttpRootURI, conf)); configureMockResponseFromHttpOrigin(this.cachedHttpFileSystem, this.originAbsoluteJarURI); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
setup
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
private static void configureMockResponseFromHttpOrigin(CachedHttpFileSystem fs, URI originAbsoluteJarURI) throws Exception { // Intercept the internal method call to request a file from a HTTP URL and return our own input stream // instead. doReturn(stringToFSDataInputStream(JAR_CONTENT)) .when(fs).downloadFromOrigin(originAbsoluteJarURI); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
configureMockResponseFromHttpOrigin
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
private static FSDataInputStream stringToFSDataInputStream(String str) { return new FSDataInputStream(new CachedHttpFileSystem.HttpDataInputStream(IOUtils.toInputStream(str))); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
stringToFSDataInputStream
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
private void assertInputStreamIsJarContent(InputStream inp) throws Exception { // Ensure the InputStream resolves to the content of our sample jar. assertEquals(JAR_CONTENT, IOUtils.toString(inp)); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
assertInputStreamIsJarContent
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
@Test public void testCachingDisabled() throws Exception { Configuration conf = new Configuration(false); // Stop FileSystem.get() from returning cached instances of CachedHttpFileSystem, it messes with our tests. // we need to create a new object each time. conf.setBoolean("fs.chttp.impl.disable.cache", true); conf.set("fs.chttp.impl", azkaban.cachedhttpfilesystem.CachedHttpFileSystem.class.getName()); conf.set(CachedHttpFileSystem.CACHE_ENABLED_FLAG, "false"); CachedHttpFileSystem tmpCachedHttpFileSystem = spy((CachedHttpFileSystem) FileSystem.get(chttpRootURI, conf)); configureMockResponseFromHttpOrigin(tmpCachedHttpFileSystem, this.originAbsoluteJarURI); // Make sure we get the content back from the origin as expected assertInputStreamIsJarContent(tmpCachedHttpFileSystem.open(new Path(this.chttpAbsoluteJarURI))); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
testCachingDisabled
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
@Test(expected = IOException.class) public void testInvalidUriPath() throws Exception { // This URI cannot be relativized against chttp://www.example.com:9000/repo/ this.cachedHttpFileSystem.open(new Path("chttp://www.wrongurl.com/some.jar"), 0); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
testInvalidUriPath
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
@Test(expected = IOException.class) public void testInvalidUriScheme() throws Exception { // This URI cannot be relativized against chttp://www.example.com:9000/repo/ (wrong scheme) this.cachedHttpFileSystem.open(new Path("http://www.wrongurl.com/repo/some.jar"), 0); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
testInvalidUriScheme
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
@Test public void testCacheMissThenHit() throws Exception { // This should be a cache miss, and populate the cache assertInputStreamIsJarContent(this.cachedHttpFileSystem.open(new Path(this.chttpAbsoluteJarURI))); // Because this was a cache miss, we expect the file queried from origin once. verify(this.cachedHttpFileSystem).downloadFromOrigin(any()); // We expect the jar file to be populated in the correct place in the cache assertTrue(this.expectedLocallyCachedJar.exists()); // **** SECOND REQUEST TO CACHEDHTTPFILESYSTEM **** // This should be a cache hit assertInputStreamIsJarContent(this.cachedHttpFileSystem.open(new Path(this.chttpAbsoluteJarURI))); // Because this was a cache hit, we do NOT expect any additional queries to the origin (still only one from // the first call) verify(this.cachedHttpFileSystem).downloadFromOrigin(any()); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
testCacheMissThenHit
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
@Test public void testCacheMissFailPersist() throws Exception { // Test the scenario where we don't find the object in the cache, but we fail to persist the object into the cache. // We should still get back an FSDataInputStream for the object from the origin. // This is a little brittle, but we have to peek inside CachedHttpFileSystem and inject our own mocked cacheFS FileSystem mockedFS = mock(FileSystem.class); // when CachedHttpFileSystem attempts to see if the file is already cached - throw FileNotFoundException (simulate // a cache miss) doThrow(new FileNotFoundException()).when(mockedFS).open(any(), anyInt()); // when CachedHttpFileSystem attempts to create the tmp file - we throw an exception. doThrow(new IOException()).when(mockedFS).create(any(), anyBoolean()); FieldSetter.setField(this.cachedHttpFileSystem, CachedHttpFileSystem.class.getDeclaredField("cacheFS"), mockedFS); // This should be a cache miss BUT should still succeed (the error opening a stream to the tmp file should be // swallowed) assertInputStreamIsJarContent(this.cachedHttpFileSystem.open(new Path(this.chttpAbsoluteJarURI))); // We do NOT expect the jar file to be persisted, because the persist failed! assertFalse(this.expectedLocallyCachedJar.exists()); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
testCacheMissFailPersist
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
@Test public void testCacheMissRaceCondition() throws Exception { // Test the scenario where we don't find the object in the cache, we download from origin, write to tmp file // but when we attempt to rename the tmp file, the rename fails because another process already persisted // this file to cache. doAnswer(i -> { // Before returning the input stream, write the file into the cache as if another process pulling the same // file from CachedHttpFileSystem beat us to the race in persisting to cache. This will result in our process // failing to rewrite the tmp file to the final file, but it should still return the InputStream just the same. FileUtils.writeStringToFile(this.expectedLocallyCachedJar, JAR_CONTENT); return stringToFSDataInputStream(JAR_CONTENT); }).when(this.cachedHttpFileSystem).downloadFromOrigin(this.originAbsoluteJarURI); // This should be a cache miss BUT should still succeed (the error renaming the file should be swallowed) assertInputStreamIsJarContent(this.cachedHttpFileSystem.open(new Path(this.chttpAbsoluteJarURI))); }
These tests use CachedHttpFileSystem with a mocked HTTP backend and a real Hadoop LocalFileSystem for caching.
testCacheMissRaceCondition
java
azkaban/azkaban
cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
https://github.com/azkaban/azkaban/blob/master/cached-http-filesystem/src/test/java/azkaban/cachedhttpfilesystem/CachedHttpFileSystemTest.java
Apache-2.0
public static ConditionFactory await() { return Awaitility.await().atMost(10L, TimeUnit.SECONDS) .pollInterval(10L, TimeUnit.MILLISECONDS); }
Wait for 10 seconds, max. Poll every 10ms.
await
java
azkaban/azkaban
test/src/main/java/azkaban/test/TestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/TestUtils.java
Apache-2.0
public static Set getDepSetABCAndNull() { return new HashSet( Arrays.asList(getDepA(), getDepB(), getDepC(), null)); }
Create and return a Set<Dependency> that contains valid objects and a null. @return Set<Dependency> containing valid objects and null
getDepSetABCAndNull
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getRawJSONDepA() { return "{" + " \"dependencies\": [" + depAJSONBlock() + " ]" + "}"; }
Create and return a Set<Dependency> that contains valid objects and a null. @return Set<Dependency> containing valid objects and null
getRawJSONDepA
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getRawJSONDepB() { return "{" + " \"dependencies\": [" + depBJSONBlock() + " ]" + "}"; }
Create and return a Set<Dependency> that contains valid objects and a null. @return Set<Dependency> containing valid objects and null
getRawJSONDepB
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getRawJSONDepC() { return "{" + " \"dependencies\": [" + depCJSONBlock() + " ]" + "}"; }
Create and return a Set<Dependency> that contains valid objects and a null. @return Set<Dependency> containing valid objects and null
getRawJSONDepC
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getRawJSONDepsAB() { return "{" + " \"dependencies\": [" + depAJSONBlock() + "," + depBJSONBlock() + " ]" + "}"; }
Create and return a Set<Dependency> that contains valid objects and a null. @return Set<Dependency> containing valid objects and null
getRawJSONDepsAB
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getRawJSONDepsABC() { return "{" + " \"dependencies\": [" + depAJSONBlock() + "," + depBJSONBlock() + "," + depCJSONBlock() + " ]" + "}"; }
Create and return a Set<Dependency> that contains valid objects and a null. @return Set<Dependency> containing valid objects and null
getRawJSONDepsABC
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getRawJSONDepsNullAndABC() { return "{" + " \"dependencies\": [" + "null," + depAJSONBlock() + "," + depBJSONBlock() + "," + depCJSONBlock() + " ]" + "}"; }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
getRawJSONDepsNullAndABC
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
private static String depAJSONBlock() { return "{" + " \"sha1\": \"131bd316a77423e6b80d93262b576c139c72b4c3\"," + " \"file\": \"aaaa.jar\"," + " \"destination\": \"lib\"," + " \"type\": \"jar\"," + " \"ivyCoordinates\": \"com.linkedin.test:testeraaaa:1.0.1\"" + "}"; }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
depAJSONBlock
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
private static String depBJSONBlock() { return "{" + " \"sha1\": \"9461919846e1e7c8fc74fee95aa6ac74993be71e\"," + " \"file\": \"bbbb.jar\"," + " \"destination\": \"dep_b_folder\"," + " \"type\": \"jar\"," + " \"ivyCoordinates\": \"com.linkedin.test:testerbbbb:1.0.1\"" + "}"; }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
depBJSONBlock
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
private static String depCJSONBlock() { return "{" + " \"sha1\": \"f873f39163f5b43dbf1fee63cbce284074896221\"," + " \"file\": \"cccc.jar\"," + " \"destination\": \"dep_c_folder\"," + " \"type\": \"jar\"," + " \"ivyCoordinates\": \"com.linkedin.test:testercccc:1.0.1\"" + "}"; }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
depCJSONBlock
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getDepAPath() { return "com/linkedin/test/testeraaaa/1.0.1/aaaa.jar"; }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
getDepAPath
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static Dependency getDepA() { try { return new Dependency( "aaaa.jar", "lib", "jar", "com.linkedin.test:testeraaaa:1.0.1", "131bd316a77423e6b80d93262b576c139c72b4c3"); } catch (Exception e) { // This will never happen throw new RuntimeException("Test utils tried to create a dependency with an invalid hash."); } }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
getDepA
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getDepBPath() { return "com/linkedin/test/testerbbbb/1.0.1/bbbb.jar"; }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
getDepBPath
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static Dependency getDepB() { try { return new Dependency( "bbbb.jar", "dep_b_folder", "jar", "com.linkedin.test:testerbbbb:1.0.1", "9461919846e1e7c8fc74fee95aa6ac74993be71e"); } catch (Exception e) { // This will never happen throw new RuntimeException("Test utils tried to create a dependency with an invalid hash."); } }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
getDepB
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static String getDepCPath() { return "com/linkedin/test/testercccc/1.0.1/cccc.jar"; }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
getDepCPath
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public static Dependency getDepC() { try { return new Dependency( "cccc.jar", "dep_c_folder", "jar", "com.linkedin.test:testercccc:1.0.1", "f873f39163f5b43dbf1fee63cbce284074896221"); } catch (Exception e) { // This will never happen throw new RuntimeException("Test utils tried to create a dependency with an invalid hash."); } }
Create a string of valid raw json that adds a null to the list of valid dependencies. @return raw json string containing valid dependencies and a null.
getDepC
java
azkaban/azkaban
test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
https://github.com/azkaban/azkaban/blob/master/test/src/main/java/azkaban/test/executions/ThinArchiveTestUtils.java
Apache-2.0
public synchronized static void lpush(String key, String... strings) { try { Jedis jedis = RedisUtil.getJedis(); jedis.lpush(key, strings); jedis.close(); } catch (Exception e) { LOGGER.error("lpush error : " + e); } }
lrem @param key @param count @param value
lpush
java
shuzheng/zheng
zheng-common/src/main/java/com/zheng/common/util/RedisUtil.java
https://github.com/shuzheng/zheng/blob/master/zheng-common/src/main/java/com/zheng/common/util/RedisUtil.java
MIT
public synchronized static void lrem(String key, long count, String value) { try { Jedis jedis = RedisUtil.getJedis(); jedis.lrem(key, count, value); jedis.close(); } catch (Exception e) { LOGGER.error("lpush error : " + e); } }
sadd @param key @param value @param seconds
lrem
java
shuzheng/zheng
zheng-common/src/main/java/com/zheng/common/util/RedisUtil.java
https://github.com/shuzheng/zheng/blob/master/zheng-common/src/main/java/com/zheng/common/util/RedisUtil.java
MIT
public static Test suite() { return new TestSuite( AppTest.class ); }
@return the suite of tests being tested
suite
java
shuzheng/zheng
zheng-demo/zheng-demo-rpc-service/src/test/java/com/zheng/AppTest.java
https://github.com/shuzheng/zheng/blob/master/zheng-demo/zheng-demo-rpc-service/src/test/java/com/zheng/AppTest.java
MIT
public static Test suite() { return new TestSuite( AppTest.class ); }
@return the suite of tests being tested
suite
java
shuzheng/zheng
zheng-pay/zheng-pay-sdk/src/test/java/com/zheng/pay/sdk/AppTest.java
https://github.com/shuzheng/zheng/blob/master/zheng-pay/zheng-pay-sdk/src/test/java/com/zheng/pay/sdk/AppTest.java
MIT
public static Test suite() { return new TestSuite( AppTest.class ); }
@return the suite of tests being tested
suite
java
shuzheng/zheng
zheng-wechat/zheng-wechat-mp/zheng-wechat-mp-service/src/test/java/com/zheng/wechat/mp/service/AppTest.java
https://github.com/shuzheng/zheng/blob/master/zheng-wechat/zheng-wechat-mp/zheng-wechat-mp-service/src/test/java/com/zheng/wechat/mp/service/AppTest.java
MIT
@Test public void useAppContext() { // Context of the app under test. Context appContext = InstrumentationRegistry.getTargetContext(); assertEquals("ccy.focuslayoutmanagerproject", appContext.getPackageName()); }
Instrumented test, which will execute on an Android device. @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
useAppContext
java
CCY0122/FocusLayoutManager
app/src/androidTest/java/ccy/focuslayoutmanagerproject/ExampleInstrumentedTest.java
https://github.com/CCY0122/FocusLayoutManager/blob/master/app/src/androidTest/java/ccy/focuslayoutmanagerproject/ExampleInstrumentedTest.java
Apache-2.0
@Test public void addition_isCorrect() { assertEquals(4, 2 + 2); }
Example local unit test, which will execute on the development machine (host). @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
addition_isCorrect
java
CCY0122/FocusLayoutManager
app/src/test/java/ccy/focuslayoutmanagerproject/ExampleUnitTest.java
https://github.com/CCY0122/FocusLayoutManager/blob/master/app/src/test/java/ccy/focuslayoutmanagerproject/ExampleUnitTest.java
Apache-2.0
@Test public void testDuration(){ assertEquals(getDuration(10f),100+20); assertEquals(getDuration(50f),100+100); assertEquals(getDuration(100f),300); assertEquals(getDuration(150f),300 + 150); assertEquals(getDuration(200f),300 + 300); }
Example local unit test, which will execute on the development machine (host). @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
testDuration
java
CCY0122/FocusLayoutManager
app/src/test/java/ccy/focuslayoutmanagerproject/ExampleUnitTest.java
https://github.com/CCY0122/FocusLayoutManager/blob/master/app/src/test/java/ccy/focuslayoutmanagerproject/ExampleUnitTest.java
Apache-2.0
public long getDuration(float distance){ float onceCompleteScrollLength = 100; long minDuration = 100; long maxDuration = 300; long duration; float distanceFraction = (Math.abs(distance) / (onceCompleteScrollLength)); if(distance <= onceCompleteScrollLength){ duration = (long) (minDuration + (maxDuration - minDuration) * distanceFraction); }else { duration = (long) (maxDuration * distanceFraction); } return duration; }
Example local unit test, which will execute on the development machine (host). @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
getDuration
java
CCY0122/FocusLayoutManager
app/src/test/java/ccy/focuslayoutmanagerproject/ExampleUnitTest.java
https://github.com/CCY0122/FocusLayoutManager/blob/master/app/src/test/java/ccy/focuslayoutmanagerproject/ExampleUnitTest.java
Apache-2.0
@Test public void useAppContext() { // Context of the app under test. Context appContext = InstrumentationRegistry.getTargetContext(); assertEquals("ccy.focuslayoutmanager.test", appContext.getPackageName()); }
Instrumented test, which will execute on an Android device. @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
useAppContext
java
CCY0122/FocusLayoutManager
focuslayoutmanager/src/androidTest/java/ccy/focuslayoutmanager/ExampleInstrumentedTest.java
https://github.com/CCY0122/FocusLayoutManager/blob/master/focuslayoutmanager/src/androidTest/java/ccy/focuslayoutmanager/ExampleInstrumentedTest.java
Apache-2.0
@Override public void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler) { cancelAnimator(); super.onDetachedFromWindow(view, recycler); }
@param recycler @param state @param delta
onDetachedFromWindow
java
CCY0122/FocusLayoutManager
focuslayoutmanager/src/main/java/ccy/focuslayoutmanager/FocusLayoutManager.java
https://github.com/CCY0122/FocusLayoutManager/blob/master/focuslayoutmanager/src/main/java/ccy/focuslayoutmanager/FocusLayoutManager.java
Apache-2.0