public void aGrepResultsSetWithSingleFileMultipleExtracts() { GrepResults results = grep(constantExpression("ERROR 1"), on(localProfile()), extraLinesAfter(20)); for (GrepResult result : results.filterBy(regularExpression("f(.*)e")).filterBy(regularExpression("ext(.*)ct"))) { assertThat(StringUtils.contains(result.getText(), "fine extract"), is(true)); } }
public void filterAndCounting() { GrepResults results = grep(constantExpression("ERROR 1"), on(localProfile()), extraLinesAfter(20)); assertThat( results .filterBy(regularExpression("Marco(.*)has been")) .filterBy(constantExpression("(id=12345)")) .totalLines(), is(1)); }
public void aGrepResultsSetWithSingleFile() { GrepResults results = grep(constantExpression("ERROR 1"), on(localProfile()), extraLinesAfter(20)); for (GrepResult result : results.filterBy(regularExpression("Marco(.*)has been"))) { assertThat( StringUtils.contains( result.getText(), "customer Marco(id=12345) has been updated successfully"), is(true)); } }
public void aGrepResultsSetWithMultipleFiles() { GrepResults results = grep( constantExpression("er"), on(Arrays.asList(localProfileWithWildecard("*"))), extraLinesAfter(20), ignoreCase()); for (GrepResult result : results.filterBy(regularExpression("ER(.*)OR"))) { if (result.getFileName().endsWith("gz")) { assertThat(StringUtils.contains(result.getText(), "GZ ERROR 1"), is(true)); assertThat(StringUtils.contains(result.getText(), "GZ ERROR 2"), is(true)); } else { assertThat(StringUtils.contains(result.getText(), "ERROR 1"), is(true)); assertThat(StringUtils.contains(result.getText(), "ERROR 2"), is(true)); } } }
@Override public GrepResults execute(List<GrepRequest> grepRequests) { GrepResults results = new GrepResults(); ExecutorService executorService = null; StackSessionPool.getInstance().startPool(); try { clock.start(); executorService = Executors.newFixedThreadPool( maxGrepTaskThreads(this.optionsDecorator, grepRequests.size())); List<GrepTask> grepTasks = new ArrayList<GrepTask>(); for (GrepRequest grepRequest : grepRequests) { grepTasks.add(new GrepTask(grepRequest)); } List<Future<List<GrepResult>>> grepTaskFutures = executorService.invokeAll(grepTasks); for (Future<List<GrepResult>> future : grepTaskFutures) { for (GrepResult singleGrepResult : future.get()) results.add(singleGrepResult); } } catch (Exception e) { throw new RuntimeException("Error when executing the GrepTask", e); } finally { clock.stop(); results.setExecutionTime(clock.getTime()); if (executorService != null) { executorService.shutdownNow(); } try { StackSessionPool.getInstance().getPool().close(); } catch (UnsupportedOperationException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } return results; }