/** * Load job schedules from the given directories * * @param dirs The directories to check for properties * @param suffixes The suffixes to load * @return The properties */ public static Props loadPropsInDirs(List<File> dirs, String... suffixes) { Props props = new Props(); for (File dir : dirs) { props.putLocal(loadPropsInDir(dir, suffixes)); } return props; }
public void run() { while (true) { /* * Processor Lock */ m_oProcessor.Lock(); boolean lbTempDisTransLog = Props.TestProp("TRANSPORTLOG", "1"); if (lbTempDisTransLog) Props.Set("TRANSPORTLOG", "0"); try { m_oProcessor.Idle(); } catch (IOException e1) { e1.printStackTrace(); } if (lbTempDisTransLog) Props.Set("TRANSPORTLOG", "1"); /* * Processor Unlock */ m_oProcessor.Unlock(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }
public static void startFrontend(Address joinAddress) { ActorSystem system = ActorSystem.create(systemName); Cluster.get(system).join(joinAddress); ActorRef frontend = system.actorOf(Props.create(Frontend.class), "frontend"); system.actorOf(Props.create(WorkProducer.class, frontend), "producer"); system.actorOf(Props.create(WorkResultConsumer.class), "consumer"); }
public Object get(String key, Object defaultValue) { for (Props p : layers) { Object result = p.get(key, null); if (result != null) return result; } return global.get(key, defaultValue); }
/** * Entry point for processing saved view state. * * @param file project file * @param varData view state var data * @param fixedData view state fixed data * @throws IOException */ public void process(ProjectFile file, Var2Data varData, byte[] fixedData) throws IOException { Props props = getProps(varData); // System.out.println(props); if (props != null) { String viewName = MPPUtility.removeAmpersands(props.getUnicodeString(VIEW_NAME)); byte[] listData = props.getByteArray(VIEW_CONTENTS); List<Integer> uniqueIdList = new LinkedList<Integer>(); if (listData != null) { for (int index = 0; index < listData.length; index += 4) { Integer uniqueID = Integer.valueOf(MPPUtility.getInt(listData, index)); // // Ensure that we have a valid task, and that if we have and // ID of zero, this is the first task shown. // if (file.getTaskByUniqueID(uniqueID) != null && (uniqueID.intValue() != 0 || index == 0)) { uniqueIdList.add(uniqueID); } } } int filterID = MPPUtility.getShort(fixedData, 128); ViewState state = new ViewState(file, viewName, uniqueIdList, filterID); file.getViews().setViewState(state); } }
public static ProcessEntryPoint createForArguments(String[] args) { Props props = ConfigurationUtils.loadPropsFromCommandLineArgs(args); ProcessCommands commands = new DefaultProcessCommands( props.nonNullValueAsFile(PROPERTY_SHARED_PATH), Integer.parseInt(props.nonNullValue(PROPERTY_PROCESS_INDEX))); return new ProcessEntryPoint(props, new SystemExit(), commands); }
@Test public void testEnvironment() { Props props = new Props(); assertEquals(0, props.countTotalProperties()); props.loadEnvironment("env"); assertTrue(props.countTotalProperties() > 0); }
@Test public void testProperties() throws IOException { Props p = loadProps("test.properties"); assertEquals("value", p.getValue("one")); assertEquals("long valuein two lines", p.getValue("two")); assertEquals("some utf8 šđžčć", p.getValue("three")); }
public Iterable<String> keys() { HashSet<String> result = new HashSet<String>(); for (Props layer : layers) { for (String key : layer.keys()) result.add(key); } for (String key : global.keys()) result.add(key); return result; }
@Test public void testDefaultProfile() { Props p = new Props(); p.load("key1=hello\n" + "key1<one>=Hi!\n" + " \n" + "@profiles=one"); assertEquals("Hi!", p.getValue("key1")); assertEquals("Hi!", p.getValue("key1", "one")); }
@Test public void testMacros2() throws IOException { Props p = new Props(); p.setValue("key1", "**${key${key3}}**"); p.setValue("key3", "2"); p.setValue("key2", "++++"); assertEquals("**++++**", p.getValue("key1")); }
@Test public void testMultilineValue() throws IOException { Props p = new Props(); p.setValueTrimLeft(true); p.load(readDataFile("test3.props")); assertEquals("\r\n\tHello from\r\n\tthe multiline\r\n\tvalue\r\n", p.getValue("email.footer")); assertEquals("aaa", p.getValue("email.header")); }
@Test public void testEscapeNewValue() throws IOException { Props p = new Props(); p.setEscapeNewLineValue("<br>"); p.load(readDataFile("test.props")); assertEquals( "Snow White, pursued by a jealous queen, hides with the Dwarfs; <br>the queen feeds her a poison apple, but Prince Charming <br>awakens her with a kiss.", p.getValue("plot")); }
@Test public void testIgnorePrefixWhitespace() throws IOException { Props p = new Props(); p.setIgnorePrefixWhitespacesOnNewLine(false); p.load(readDataFile("test.props")); assertEquals( "Snow White, pursued by a jealous queen, hides with the Dwarfs; \t\tthe queen feeds her a poison apple, but Prince Charming \t\tawakens her with a kiss.", p.getValue("plot")); }
@Test public void loadPropsFromCommandLineArgs_load_properties_from_file() throws Exception { File propsFile = temp.newFile(); FileUtils.write(propsFile, "foo=bar"); Props result = ConfigurationUtils.loadPropsFromCommandLineArgs(new String[] {propsFile.getAbsolutePath()}); assertThat(result.value("foo")).isEqualTo("bar"); assertThat(result.rawProperties()).hasSize(1); }
public static Map<String, Object> toHierarchicalMap(Props props) { Map<String, Object> propsMap = new HashMap<String, Object>(); propsMap.put("source", props.getSource()); propsMap.put("props", toStringMap(props, true)); if (props.getParent() != null) { propsMap.put("parent", toHierarchicalMap(props.getParent())); } return propsMap; }
@Test public void testActiveProfiles() throws IOException { Props p = loadProps("test-actp.props"); assertEquals("hello", p.getBaseValue("key1")); assertEquals("Hola!", p.getValue("key1")); assertEquals("world", p.getValue("key2")); assertEquals(1, p.getActiveProfiles().length); assertEquals("one.two", p.getActiveProfiles()[0]); }
public static Map<String, String> toStringMap(Props props, boolean localOnly) { HashMap<String, String> map = new HashMap<String, String>(); Set<String> keyset = localOnly ? props.localKeySet() : props.getKeySet(); for (String key : keyset) { String value = props.get(key); map.put(key, value); } return map; }
@Test public void testMacroNotExist() { Props p = new Props(); p.setValue("mac1", "value1"); p.setValue("key1", "${mac1}"); p.setValue("key2", "${mac2}"); assertEquals("value1", p.getValue("mac1")); assertEquals("value1", p.getValue("key1")); assertEquals("${mac2}", p.getValue("key2")); }
@Test public void testingWithCustomProps() { TestProbe probe = new TestProbe(system); Props childProps = Props.create(MockedChild.class); TestActorRef<DependentParent> parent = TestActorRef.create(system, Props.create(DependentParent.class, childProps)); probe.send(parent, "pingit"); // test some parent state change assertTrue(parent.underlyingActor().ponged == true || parent.underlyingActor().ponged == false); }
/** * Test validates the happy path when an log viewer is configured with '${execid}' and '${jobid} * as the format in 'azkaban.properties'. */ @Test public void testGetExternalLogViewerValidFormat() { azkProps.put( ServerProperties.AZKABAN_SERVER_EXTERNAL_LOGVIEWER_TOPIC, EXTERNAL_LOGVIEWER_TOPIC); azkProps.put( ServerProperties.AZKABAN_SERVER_EXTERNAL_TOPIC_URL.replace( "${topic}", EXTERNAL_LOGVIEWER_TOPIC), EXTERNAL_LOGVIEWER_URL_VALID_FORMAT); String externalURL = ExternalLinkUtils.getExternalLogViewer(azkProps, jobId, jobProps); assertTrue(externalURL.equals(EXTERNAL_LOGVIEWER_EXPECTED_URL)); }
/** * Test validates the happy path when an external analyzer is configured with '${url}' as the * format in 'azkaban.properties'. */ @Test public void testGetExternalAnalyzerValidFormat() { azkProps.put(ServerProperties.AZKABAN_SERVER_EXTERNAL_ANALYZER_TOPIC, EXTERNAL_ANALYZER_TOPIC); azkProps.put( ServerProperties.AZKABAN_SERVER_EXTERNAL_TOPIC_URL.replace( "${topic}", EXTERNAL_ANALYZER_TOPIC), EXTERNAL_ANALYZER_URL_VALID_FORMAT); when(mockRequest.getRequestURL()).thenReturn(new StringBuffer(EXEC_URL)); when(mockRequest.getQueryString()).thenReturn(EXEC_QUERY_STRING); String externalURL = ExternalLinkUtils.getExternalAnalyzerOnReq(azkProps, mockRequest); assertTrue(externalURL.equals(EXTERNAL_ANALYZER_EXPECTED_URL)); }
@SuppressWarnings("unchecked") public static Props fromHierarchicalMap(Map<String, Object> propsMap) { if (propsMap == null) { return null; } String source = (String) propsMap.get("source"); Map<String, String> propsParams = (Map<String, String>) propsMap.get("props"); Map<String, Object> parent = (Map<String, Object>) propsMap.get("parent"); Props parentProps = fromHierarchicalMap(parent); Props props = new Props(parentProps, propsParams); props.setSource(source); return props; }
@Test public void verifyResult() { SignerBoundFieldsExample signerBoundFieldsExample = new SignerBoundFieldsExample(Props.get()); signerBoundFieldsExample.run(); DocumentPackage documentPackage = signerBoundFieldsExample.getRetrievedPackage(); for (Signature signature : documentPackage.getDocument(SignerBoundFieldsExample.DOCUMENT_NAME).getSignatures()) { for (Field field : signature.getFields()) { if ((int) (field.getX() + 0.1) == SignerBoundFieldsExample.SIGNATURE_DATE_POSITION_X && (int) (field.getY() + 0.1) == SignerBoundFieldsExample.SIGNATURE_DATE_POSITION_Y) { assertThat(field.getPage(), is(equalTo(SignerBoundFieldsExample.SIGNATURE_DATE_PAGE))); assertThat(field.getStyle(), is(equalTo(FieldStyle.BOUND_DATE))); } if ((int) (field.getX() + 0.1) == SignerBoundFieldsExample.SIGNER_COMPANY_POSITION_X && (int) (field.getY() + 0.1) == SignerBoundFieldsExample.SIGNER_COMPANY_POSITION_Y) { assertThat(field.getPage(), is(equalTo(SignerBoundFieldsExample.SIGNER_COMPANY_PAGE))); assertThat(field.getStyle(), is(equalTo(FieldStyle.BOUND_COMPANY))); } if ((int) (field.getX() + 0.1) == SignerBoundFieldsExample.SIGNER_NAME_POSITION_X && (int) (field.getY() + 0.1) == SignerBoundFieldsExample.SIGNER_NAME_POSITION_Y) { assertThat(field.getPage(), is(equalTo(SignerBoundFieldsExample.SIGNER_NAME_PAGE))); assertThat(field.getStyle(), is(equalTo(FieldStyle.BOUND_NAME))); } if ((int) (field.getX() + 0.1) == SignerBoundFieldsExample.SIGNER_TITLE_POSITION_X && (int) (field.getY() + 0.1) == SignerBoundFieldsExample.SIGNER_TITLE_POSITION_Y) { assertThat(field.getPage(), is(equalTo(SignerBoundFieldsExample.SIGNER_TITLE_PAGE))); assertThat(field.getStyle(), is(equalTo(FieldStyle.BOUND_TITLE))); } } } }
/** * Make sure that URLs for analyzers and logviewers are fetched correctly by setting it manually * and then fetching them */ @Test public void testFetchURL() { azkProps.put( ServerProperties.AZKABAN_SERVER_EXTERNAL_TOPIC_URL.replace("${topic}", "someTopic"), "This is a link"); assertTrue(ExternalLinkUtils.getURLForTopic("someTopic", azkProps).equals("This is a link")); }
@Test public void testingWithoutParent() { TestProbe probe = new TestProbe(system); ActorRef child = system.actorOf(Props.create(DependentChild.class, probe.ref())); probe.send(child, "ping"); probe.expectMsg("pong"); }
public void initLoader() { BufferedReader reader = new BufferedReader( new InputStreamReader( ResourceLoader.getResourceAsStream(Props.getPropStr("Resource.Picture.Path")))); try { String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (line == null || line.isEmpty() || line.startsWith("#")) { continue; } String[] args = line.split(";"); String key = args[0].trim(); String path = args[1].trim(); try { images.put(key, new Image(ResourceLoader.getResourceAsStream(path), path, false)); } catch (SlickException ex) { LOGGER.log(Level.WARNING, "Unable to create image " + path, ex); } } } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Unable to initialise the picture loader", ex); } }
@Test public void verifyResult() { DocumentPackageAttributesExample documentPackageAttributesExample = new DocumentPackageAttributesExample(Props.get()); documentPackageAttributesExample.run(); DocumentPackage documentPackage = documentPackageAttributesExample.getRetrievedPackage(); DocumentPackageAttributes documentPackageAttributes = documentPackage.getAttributes(); Map<String, Object> attributeMap = documentPackageAttributes.getContents(); assertThat( "Attribute key 1 is not setup correctly.", attributeMap.containsKey(ATTRIBUTE_KEY_1)); assertThat( "Attribute key 2 is not setup correctly.", attributeMap.containsKey(ATTRIBUTE_KEY_2)); assertThat( "Attribute key 3 is not setup correctly.", attributeMap.containsKey(ATTRIBUTE_KEY_3)); assertThat( "Attribute 1 is not setup correctly.", attributeMap.get(ATTRIBUTE_KEY_1).toString().equals(ATTRIBUTE_1)); assertThat( "Attribute 2 is not setup correctly.", attributeMap.get(ATTRIBUTE_KEY_2).toString().equals(ATTRIBUTE_2)); assertThat( "Attribute 3 is not setup correctly.", attributeMap.get(ATTRIBUTE_KEY_3).toString().equals(ATTRIBUTE_3)); }
public static void startWorker(Address contactAddress) { ActorSystem system = ActorSystem.create(systemName); Set<ActorSelection> initialContacts = new HashSet<ActorSelection>(); initialContacts.add(system.actorSelection(contactAddress + "/user/receptionist")); ActorRef clusterClient = system.actorOf(ClusterClient.defaultProps(initialContacts), "clusterClient"); system.actorOf(Worker.props(clusterClient, Props.create(WorkExecutor.class)), "worker"); }
@Test public void useAsk() throws Exception { ActorRef testActor = system.actorOf(Props.create(JavaAPITestActor.class), "test"); assertEquals( "Ask should return expected answer", JavaAPITestActor.ANSWER, Await.result(ask(testActor, "hey!", 3000), Duration.create(3, "seconds"))); }