public DiscoApiModel(Document document, String defaultPackageName) { this.document = document; this.diagCollector = new BoundedDiagCollector(); this.defaultPackageName = defaultPackageName; }
@Override public boolean hasErrors() { return getErrorCount() > 0; }
@Override public int getErrorCount() { return getErrors().size(); }
@Test public void testTooManyWarnings() { // It should stop accumulating warnings after `count` of them. for (int i = 0; i < WARNING_MAX_COUNT + 5; i++) { diagCollector.addDiag( Diag.warning( new SimpleLocation(String.format("testTooManyWarnings:%d", i)), "%s", "This is a warning message")); } // We should have `count` warnings plus the "too many" warning in the diagnostics. Assert.assertEquals(WARNING_MAX_COUNT + 1, diagCollector.getDiags().size()); Assert.assertEquals(0, diagCollector.getErrorCount()); }
public List<Diag> getErrors() { return listByKind(Kind.ERROR); }
@Test public void testTooManyErrors() { try { for (int i = 0; i < ERROR_MAX_COUNT + 5; i++) { diagCollector.addDiag( Diag.error( new SimpleLocation(String.format("testTooManyErrors:%d", i)), "%s", "This is an error message")); } Assert.fail("Expected TooManyDiagsException was not thrown"); } catch (TooManyDiagsException ex) { // fall through to assertions } // We should have `count` errors plus the "too many" error in the diagnostics. Assert.assertEquals(ERROR_MAX_COUNT + 1, diagCollector.getDiags().size()); Assert.assertEquals(ERROR_MAX_COUNT + 1, diagCollector.getErrorCount()); }
public List<Diag> getErrors() { return listByKind(Kind.ERROR); }
@Before public void before() { diagCollector = new BoundedDiagCollector( ImmutableMap.<Kind, Integer>builder() .put(Kind.ERROR, ERROR_MAX_COUNT) .put(Kind.WARNING, WARNING_MAX_COUNT) .build()); }
@Test public void testTooManyMixedDiags() { try { for (int i = 0; i < WARNING_MAX_COUNT + 5; i++) { diagCollector.addDiag( Diag.warning( new SimpleLocation(String.format("testTooManyMixedDiags:%d", i)), "%s", "This is a warning message")); } for (int i = 0; i < ERROR_MAX_COUNT + 5; i++) { diagCollector.addDiag( Diag.error( new SimpleLocation(String.format("testTooManyMixedDiags:%d", i)), "%s", "This is an error message")); } Assert.fail("Expected TooManyDiagsException was not thrown"); } catch (TooManyDiagsException ex) { // fall through to assertions } // We should have `warnCount` warnings plus the "too many" warning in the diagnostics, plus // `errorCount` errors and the "too many" error. Assert.assertEquals( WARNING_MAX_COUNT + 1 + ERROR_MAX_COUNT + 1, diagCollector.getDiags().size()); Assert.assertEquals(ERROR_MAX_COUNT + 1, diagCollector.getErrorCount()); } }
@Override public boolean hasErrors() { return getErrorCount() > 0; }
@Override public void addDiag(Diag diag) { int capacity = capacityByKind.containsKey(diag.getKind()) ? capacityByKind.get(diag.getKind()) : 0; int currentCount = listByKind(diag.getKind()).size(); if (currentCount < capacity) { diags.add(diag); } else if (currentCount == capacity) { final String msg = String.format( "Hit max count(%d) of allowed %s. No more diags of this kind will be logged.", capacity, StringUtils.lowerCase(diag.getKind().toString())); diags.add(Diag.create(SimpleLocation.TOPLEVEL, "%s", diag.getKind(), msg)); // Try to short circuit proceeding in a known bad state (to avoid potential timeouts in // trying process REALLY bad configuration). if (diag.getKind() == Kind.ERROR) { throw new TooManyDiagsException(msg); } } }
@Override public int getErrorCount() { return getErrors().size(); }
/** * Creates a new model based on the given file descriptor, list of source file names and list of * experiments to be enabled for the model. */ public static Model create( FileDescriptorSet proto, Iterable<String> sources, Experiments experiments, ExtensionPool extensionPool) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, sources, experiments, extensionPool, diagCollector, new DiagSuppressor(diagCollector)); }
@Override public void addDiag(Diag diag) { int capacity = capacityByKind.containsKey(diag.getKind()) ? capacityByKind.get(diag.getKind()) : 0; int currentCount = listByKind(diag.getKind()).size(); if (currentCount < capacity) { diags.add(diag); } else if (currentCount == capacity) { final String msg = String.format( "Hit max count(%d) of allowed %s. No more diags of this kind will be logged.", capacity, StringUtils.lowerCase(diag.getKind().toString())); diags.add(Diag.create(SimpleLocation.TOPLEVEL, "%s", diag.getKind(), msg)); // Try to short circuit proceeding in a known bad state (to avoid potential timeouts in // trying process REALLY bad configuration). if (diag.getKind() == Kind.ERROR) { throw new TooManyDiagsException(msg); } } }
/** * Creates a new model based on the given file descriptor, list of source file names and list of * experiments to be enabled for the model. */ public static Model create( FileDescriptorSet proto, Iterable<String> sources, Experiments experiments, ExtensionPool extensionPool) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, sources, experiments, extensionPool, diagCollector, new DiagSuppressor(diagCollector)); }
/** Creates an model where all protos in the descriptor are considered to be sources. */ public static Model create(FileDescriptorSet proto) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, null, ExperimentsImpl.none(), ExtensionPool.EMPTY, diagCollector, new DiagSuppressor(diagCollector)); }
/** Creates an model where all protos in the descriptor are considered to be sources. */ public static Model create(FileDescriptorSet proto) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, null, ExperimentsImpl.none(), ExtensionPool.EMPTY, diagCollector, new DiagSuppressor(diagCollector)); }
/** * Creates a new model based on the given file descriptor set and list of source file names. The * file descriptor set is self-contained and contains the descriptors for the source files as well * as for all dependencies. */ public static Model create(FileDescriptorSet proto, Iterable<String> sources) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, sources, ExperimentsImpl.none(), ExtensionPool.EMPTY, diagCollector, new DiagSuppressor(diagCollector)); }
/** * Creates a new model based on the given file descriptor set and list of source file names. The * file descriptor set is self-contained and contains the descriptors for the source files as well * as for all dependencies. */ public static Model create(FileDescriptorSet proto, Iterable<String> sources) { DiagCollector diagCollector = new BoundedDiagCollector(); return new Model( proto, sources, ExperimentsImpl.none(), ExtensionPool.EMPTY, diagCollector, new DiagSuppressor(diagCollector)); }
@Test public void testCreateLROWithNonLROMethod() { DiagCollector diagCollector = new BoundedDiagCollector(); LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( simpleMethod, diagCollector, LongRunningConfigProto.getDefaultInstance(), protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNull(); } }