@Transactional(readOnly = true) @Test public void testGetWidgetDefinitionsByCategory() throws IOException, Exception { SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(auth); MultiMap widgetDefinitionsByCategoryMap = uIService.getWidgetDefinitionsByCategory(); Assert.notNull(widgetDefinitionsByCategoryMap); // Assert.isTrue(widgetDefinitionsByCategoryMap.size() == 3); // Assert.isTrue(widgetDefinitionsByCategoryMap.values().size() == 4); org.junit.Assert.assertTrue( "testGetWidgetDefinitionsByCategory() widgetDefinitionsByCategoryMap.size() failed test, " + "expected value 3, actually got: " + widgetDefinitionsByCategoryMap.size(), widgetDefinitionsByCategoryMap.size() == 4); org.junit.Assert.assertTrue( "testGetWidgetDefinitionsByCategory() widgetDefinitionsByCategoryMap.values().size() failed test, " + "expected value 4, actually got: " + widgetDefinitionsByCategoryMap.values().size(), widgetDefinitionsByCategoryMap.values().size() >= 5); securityContext.setAuthentication(null); }
/** * Returns all values for the given key * * @param key key (case insensitive) * @return all values of the given header or {@code null}, if there is no such a key in this * instance */ public List<String> getValues(final String key) { Validate.notEmpty(key, "name cannot be empty"); @SuppressWarnings("unchecked") final List<String> result = (List<String>) values.get(key.toLowerCase()); return result == null || result.isEmpty() ? null : new ArrayList<String>(result); }
/** * Indexes a set of reports, using Start and End tags output is a list of entries of the form: A: * time1,time2,time3 * * <p>If no matches, will return an empty array */ @SuppressWarnings("unchecked") public static Text[] indexGraph(Map<String, Report> reports) { org.apache.commons.collections.MultiMap index = new org.apache.commons.collections.MultiHashMap(); // map from start tag to opIds of nodes containing the ends for (Map.Entry<String, Report> report : reports.entrySet()) { Report start = report.getValue(); List<String> starts = start.get("Start"); if (starts != null) { for (String s : starts) { Report end = findMatchingEnd(reports, start, s); if (end == null) continue; List<String> endTL = end.get("Timestamp"); List<String> staTL = start.get("Timestamp"); if (staTL != null && endTL != null && staTL.size() > 0 && endTL.size() > 0) { // FIXME: perhaps parse more cleverly? double startT = Double.parseDouble(staTL.get(0)); double endT = Double.parseDouble(endTL.get(0)); Long diff = new Long((long) (1000 * (endT - startT))); index.put(s, diff); } } } } Text[] out = new Text[index.size()]; int i = 0; for (Object k : index.keySet()) { StringBuilder sb = new StringBuilder(); sb.append(k.toString()); sb.append(' '); Collection coll = (Collection) index.get(k); for (Object v : coll) { assert v instanceof Long : "how did a non-Long get into my collection?"; sb.append(v.toString()); sb.append(","); } sb.deleteCharAt(sb.length() - 1); Text t = new Text(sb.toString()); out[i++] = t; } return out; }
/** * Fusionne la MultiMap avec celle-ci. C'est à dire rajoute les valeurs de mm à la suite des * valeurs de cette map (contrairement à putAll(Map) qui ajoute les valeurs de mm en tant que * valeur scalaire et non en tant que collection). * * @param mm la MultiMap à fusionner. */ public void merge(MultiMap mm) { // copied from super ctor for (Iterator it = mm.entrySet().iterator(); it.hasNext(); ) { final Map.Entry entry = (Map.Entry) it.next(); Collection<V> coll = (Collection<V>) entry.getValue(); Collection newColl = createCollection(coll); this.putAll(entry.getKey(), newColl); } }
/** * Evaluates a solution. * * @param solution The solution to evaluate. * @throws JMException */ public void evaluate(Solution solution) throws JMException { writeModificationFile(solution); String energyPLANrunCommand = ".\\EnergyPLAN_SEP_2013\\EnergyPLAN.exe -i \".\\EnergyPLAN_SEP_2013\\energyPlan data\\Data\\RefModelForOptimization.txt\" -m \"modification.txt\" -ascii \"result.txt\" "; try { // Process process = new // ProcessBuilder(energyPLANrunCommand).start(); Process process = Runtime.getRuntime().exec(energyPLANrunCommand); process.waitFor(); process.destroy(); EnergyPLANFileParse epfp = new EnergyPLANFileParse(".\\result.txt"); energyplanmMap = epfp.parseFile(); Iterator it; Collection<String> col; col = (Collection<String>) energyplanmMap.get("CO2-emission (total)"); it = col.iterator(); solution.setObjective(0, Double.parseDouble(it.next().toString())); col = (Collection<String>) energyplanmMap.get("TOTAL ANNUAL COSTS"); it = col.iterator(); solution.setObjective(1, Double.parseDouble(it.next().toString())); // check warning col = (Collection<String>) energyplanmMap.get("WARNING"); if (col != null) { /* System.out.println("No warning"); } else {*/ @SuppressWarnings("rawtypes") Iterator it3 = col.iterator(); if (!it3.next().toString().equals("PP too small. Critical import is needed")) throw new IOException("warning!!" + it3.next().toString()); // System.out.println("Warning " + it3.next().toString()); } } catch (IOException e) { System.out.println("Energyplan.exe has some problem"); e.printStackTrace(); } catch (InterruptedException e) { System.out.println("Energyplan interrupted"); } }
@After public void clearAllQueue() throws Exception { for (String name : queueNameList) { final boolean result = this.rabbitAdmin.deleteQueue(name); LOG.debug( (result) ? "\t\tQueue Deletion Successful for: " + name : "\t\tQueue Deletion UnSuccessful for: " + name); } for (Object queueName : pushedQueueMap.keySet()) { final boolean result = this.rabbitAdmin.deleteQueue((String) queueName); LOG.debug( (result) ? "\t\tQueue Deletion Successful for: " + queueName : "\t\tQueue Deletion UnSuccessful for: " + queueName); } queueNameList.clear(); pushedQueueMap.clear(); }
@SuppressWarnings("unchecked") public void evaluateConstraints(Solution solution) throws JMException { Iterator it; Collection<String> col; col = (Collection<String>) energyplanmMap.get("Maximumimport"); it = col.iterator(); int maximumImport = Integer.parseInt(it.next().toString()); double constrints = 2500 - maximumImport; if (constrints < 0.0) { solution.setOverallConstraintViolation(constrints); solution.setNumberOfViolatedConstraint(1); } else { solution.setOverallConstraintViolation(0.0); solution.setNumberOfViolatedConstraint(0); } }
@Test public void testPublishAndSubscribeBroadCastServiceWithSeparateThread() throws Exception { final Random random = new Random(System.currentTimeMillis()); final class LucasBroadCastServiceThread extends Thread { private LucasMessageBroadcastService lucasMessageBroadcastService; final String randomString = UUID.randomUUID().toString(); String queueName; String bindKey; String data; public LucasBroadCastServiceThread( final LucasMessageBroadcastService lucasMessageBroadcastService, final String threadName, final int priority) throws Exception { super(threadName); super.setPriority(priority); this.lucasMessageBroadcastService = lucasMessageBroadcastService; final int randomNum = random.nextInt(10) + 1; this.queueName = TEST_QUEUE_PREFIX + randomNum; this.bindKey = TEST_QUEUE_PREFIX + ".Binding" + randomNum; this.data = randomString; } @Override public void run() { try { LOG.debug("Posting queueName: " + queueName + " and data: " + data); pushedQueueMap.put(queueName, data); this.lucasMessageBroadcastService.sendMessage(queueName, bindKey, data); } catch (Exception e) { LOG.error("Exception Generated ", e); throw new LucasRuntimeException(e); } } } final class LucasBroadCastClientThread extends Thread { private LucasMessageBroadcastClientService lucasMessageBroadcastClientService; private String lucasBroadCastQueue; private String lucasBroadCastBinding; public LucasBroadCastClientThread( LucasMessageBroadcastClientService lucasMessageBroadcastClientService, String threadName, int threadPriority, String lucasBroadCastQueue, String lucasBroadCastBinding) { super(threadName); super.setPriority(threadPriority); this.lucasMessageBroadcastClientService = lucasMessageBroadcastClientService; this.lucasBroadCastBinding = lucasBroadCastBinding; this.lucasBroadCastQueue = lucasBroadCastQueue; } @Override public void run() { try { String[] stringArray = this.lucasMessageBroadcastClientService.receiveAllMessagesWithinTimePeriod( this.lucasBroadCastQueue, this.lucasBroadCastBinding, 1L, 5000L); if (stringArray != null) { for (String string : stringArray) { pulledQueueMap.put(this.lucasBroadCastQueue, string); } } } catch (Exception e) { LOG.error("Exception Generated ", e); throw new LucasRuntimeException(e); } } } // // Publisher Threads final int maxThreads = 1000; ExecutorService pushExecutor = Executors.newFixedThreadPool(maxThreads); CompletionService<?> pushCompletion = new ExecutorCompletionService(pushExecutor); for (int i = 0; i < maxThreads; i++) { LucasBroadCastServiceThread thread = new LucasBroadCastServiceThread( this.lucasBroadCastService, "LucasBroadCastServiceThread" + i, 5); pushCompletion.submit(thread, null); } for (int i = 0; i < maxThreads; ++i) { pushCompletion.take(); } pushExecutor.shutdown(); // Subscriber threads int j = 0; // Get the queueNames stored while publishing... Set<String> keySet = pushedQueueMap.keySet(); if (keySet != null) { ExecutorService pullExecutor = Executors.newFixedThreadPool(keySet.size()); CompletionService<?> pullCompletion = new ExecutorCompletionService(pullExecutor); for (String queueName : keySet) { // ...and receive on each queueName LucasBroadCastClientThread thread = new LucasBroadCastClientThread( lucasMessageBroadcastClientService, "LucasBroadCastClientThread" + j, 5, queueName, TEST_QUEUE_PREFIX + ".Binding" + j); pullCompletion.submit(thread, null); j++; } for (int i = 0; i < keySet.size(); ++i) { pullCompletion.take(); } pullExecutor.shutdown(); } LOG.debug("Pushed values:"); CollectionsUtilService.dumpMultiMapNumbers(pushedQueueMap); LOG.debug("Pulled values:"); CollectionsUtilService.dumpMultiMapNumbers(pulledQueueMap); // Assert junit.framework.Assert.assertTrue( "The pushed and pulled values do not match!", CollectionsUtilService.compareMultiMaps(pushedQueueMap, pulledQueueMap)); }
static { tagMap.put("DC.Format", MetadataField.DC_FIELD_FORMAT); tagMap.put("DC.Language", MetadataField.DC_FIELD_LANGUAGE); tagMap.put("DC.Title", MetadataField.DC_FIELD_TITLE); tagMap.put("DC.Identifier", MetadataField.DC_FIELD_IDENTIFIER); tagMap.put("DC.Date", MetadataField.DC_FIELD_DATE); tagMap.put("DC.Publisher", MetadataField.DC_FIELD_PUBLISHER); tagMap.put("DC.Publisher", MetadataField.FIELD_PUBLISHER); tagMap.put("DC.Contributor", MetadataField.DC_FIELD_CONTRIBUTOR); tagMap.put("citation_journal_title", MetadataField.FIELD_PUBLICATION_TITLE); tagMap.put("citation_title", MetadataField.FIELD_ARTICLE_TITLE); tagMap.put("citation_date", MetadataField.FIELD_DATE); tagMap.put("citation_author", MetadataField.FIELD_AUTHOR); tagMap.put( "citation_authors", new MetadataField(MetadataField.FIELD_AUTHOR, MetadataField.splitAt(";"))); tagMap.put("citation_issn", MetadataField.FIELD_ISSN); tagMap.put("citation_volume", MetadataField.FIELD_VOLUME); tagMap.put("citation_volume", MetadataField.DC_FIELD_CITATION_VOLUME); tagMap.put("citation_issue", MetadataField.FIELD_ISSUE); tagMap.put("citation_issue", MetadataField.DC_FIELD_CITATION_ISSUE); tagMap.put("citation_firstpage", MetadataField.FIELD_START_PAGE); tagMap.put("citation_lastpage", MetadataField.FIELD_END_PAGE); tagMap.put("citation_doi", MetadataField.FIELD_DOI); tagMap.put("citation_public_url", MetadataField.FIELD_ACCESS_URL); } // static
static { // <meta name="citation_doi" content="10.1088/2043-6262/1/4/043003" /> tagMap.put("citation_doi", MetadataField.FIELD_DOI); // <meta name="citation_publication_date" content="2011-01-25" /> tagMap.put("citation_publication_date", MetadataField.FIELD_DATE); // <meta name="citation_title" content="Polymer materials with spatially..." /> tagMap.put("citation_title", MetadataField.FIELD_ARTICLE_TITLE); // <meta name="citation_issn" content="2043-6262"/> tagMap.put("citation_issn", MetadataField.FIELD_ISSN); // <meta name="citation_volume" content="1" /> tagMap.put("citation_volume", MetadataField.FIELD_VOLUME); // <meta name="citation_issue" content="4"/> tagMap.put("citation_issue", MetadataField.FIELD_ISSUE); // <meta name="citation_firstpage" content="043003"/> tagMap.put("citation_firstpage", MetadataField.FIELD_START_PAGE); // <meta name="citation_author" content="Daisuke Fujiki"/> tagMap.put("citation_author", MetadataField.FIELD_AUTHOR); // <meta name="citation_journal_title" content="Advances in Natural Sciences: // Nanoscience and Nanotechnology" /> tagMap.put("citation_journal_title", MetadataField.FIELD_PUBLICATION_TITLE); // <meta name="citation_publisher" content="IOP Publishing" /> tagMap.put("citation_publisher", MetadataField.FIELD_PUBLISHER); // XXX this map is so that the metadata url is not always the access_url // <meta name="citation_fulltext_html_url" content="http://iopscience.iop.org/... tagMap.put("citation_fulltext_html_url", IOP_ACCESS_URL); }
static { tagMap.put("DC.Format", MetadataField.FIELD_FORMAT); tagMap.put("DC.Language", MetadataField.FIELD_LANGUAGE); tagMap.put("citation_publisher", MetadataField.FIELD_PUBLISHER); tagMap.put("citation_journal_title", MetadataField.FIELD_PUBLICATION_TITLE); tagMap.put("citation_title", MetadataField.FIELD_ARTICLE_TITLE); tagMap.put("citation_date", MetadataField.FIELD_DATE); tagMap.put("citation_publication_date", MetadataField.FIELD_DATE); tagMap.put( "citation_authors", new MetadataField(MetadataField.FIELD_AUTHOR, MetadataField.splitAt(";"))); tagMap.put("citation_author", MetadataField.FIELD_AUTHOR); tagMap.put("citation_issn", MetadataField.FIELD_ISSN); tagMap.put("citation_volume", MetadataField.FIELD_VOLUME); tagMap.put("citation_issue", MetadataField.FIELD_ISSUE); tagMap.put("citation_firstpage", MetadataField.FIELD_START_PAGE); tagMap.put("citation_lastpage", MetadataField.FIELD_END_PAGE); tagMap.put("citation_doi", MetadataField.FIELD_DOI); tagMap.put("citation_public_url", MetadataField.FIELD_ACCESS_URL); // typical field value: "acupmed;30/1/8": extract "acupmed" tagMap.put( "citation_mjid", new MetadataField( MetadataField.FIELD_PROPRIETARY_IDENTIFIER, MetadataField.extract("^([^;]+);", 1))); }