HardSoftCodeLimiter implements CodeLimiter { public static Builder builder() { return new Builder(); } private  HardSoftCodeLimiter(int softLimit, int hardLimit, int resolution, Handler handler); static Builder builder(); int instructionCount(); int softLimit(); int hardLimit(); void check();  }
@Test public void testNoLimit() throws CodeException { JsonNode node = JsonUtils.decode("[0,1,2,3,4,5,6,7,8,9]"); Context ctx = new Context(node); RootInst root = builder().repeated("@").var("@").end().eof().build(); ctx.execute(root); assertEquals(ctx.buffer().toString(), "0123456789"); }
@Test public void testBothLimits() throws CodeException { final AtomicInteger softCount = new AtomicInteger(); final AtomicInteger hardCount = new AtomicInteger(); HardSoftCodeLimiter.Handler handler = new HardSoftCodeLimiter.Handler() { @Override public void onLimit(Limit limit, HardSoftCodeLimiter limiter) throws CodeExecuteException { if (limit.equals(Limit.SOFT)) { softCount.incrementAndGet(); } if (limit.equals(Limit.HARD)) { hardCount.incrementAndGet(); } } }; CodeLimiter codeLimiter = HardSoftCodeLimiter.builder() .setSoftLimit(5) .setHardLimit(10) .setResolution(1) .setHandler(handler) .build(); compiler().newExecutor() .template("{.repeated section @}{.even?}{@}{.or}#{.end}{.end}") .json("[0,1,2,3,4,5,6,7,8,9]") .codeLimiter(codeLimiter) .execute(); assertEquals(softCount.get(), 1); assertEquals(hardCount.get(), 1); }