TraceReader { public void read(String filename) { FileSystemUtil.assertFileOrResourceExists(filename); try { List<List<Span>> traces = mapper.readValue(new File(filename), new TypeReference<List<List<Span>>>() { }); LOGGER.info("Read traces: {}", traces.size()); analyzeAllTraces(traces); } catch (IOException e) { LOGGER.error("Can't read file {}", FileNameUtil.getCanonicalPath(filename), e); throw new IllegalArgumentException(e); } } TraceReader(DependencyGraph dependencyGraph); void read(String filename); static final String TYPE_SPAN; static final String SCOPE_TRACE_ENDPOINT; static final String SCOPE_TRACE_SERVICE; static final String TRACES_PARENT_KEY; static final String PLACEHOLDER_NAME; }
@Test public void testNotExistingFile() { try { traceReader.read("/not/existing/file"); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).startsWith("File not found: "); } }
@Test public void testNoJsonFile() { try { traceReader.read("src/test/resources/traces/noJsonFile.txt"); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getCause()).isInstanceOf(IOException.class); assertThat(e.getMessage()).startsWith("com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'This': was expecting ('true', 'false' or 'null')"); } }