@Test public void checkUnlimitRequestsForKey() throws Exception { PrivateKey myKey = TestKeys.privateKey(3); List<Main> mm = new ArrayList<>(); for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), false)); mm.forEach(x -> x.config.setIsFreeRegistrationsAllowedFromYaml(true)); Main main = mm.get(0); Client client = null; try { client = new Client(myKey, main.myInfo, null); } catch (Exception e) { System.out.println("prepareClient exception: " + e.toString()); } Set<PublicKey> ownerKeys = new HashSet(); Set<PrivateKey> keys = new HashSet(); keys.add(myKey); ownerKeys.add(myKey.getPublicKey()); Contract payment = InnerContractsService.createFreshU(100000000, ownerKeys); payment.check(); payment.traceErrors(); client.register(payment.getPackedTransaction()); Thread.currentThread().sleep(5000); mm.forEach(x -> x.config.setIsFreeRegistrationsAllowedFromYaml(false)); long seconds = ZonedDateTime.now().toEpochSecond() % 60; if (seconds > 57) Thread.currentThread().sleep(3000); for (int i = 0; i < main.config.getLimitRequestsForKeyPerMinute(); i++) System.out.println(">> storage rate: " + client.storageGetRate()); String exception = ""; try { client.storageGetRate(); } catch (Exception e) { System.out.println("Client exception: " + e.toString()); exception = e.getMessage(); } assertEquals(exception, "ClientError: COMMAND_FAILED exceeded the limit of requests for key per minute," + " please call again after a while"); Contract unlimitContract = ContractsService.createRateLimitDisablingContract( myKey.getPublicKey(), payment, main.config.getRateLimitDisablingPayment(), keys); unlimitContract.check(); unlimitContract.traceErrors(); assertTrue(unlimitContract.isOk()); ItemResult itemResult = client.register(unlimitContract.getPackedTransaction()); Thread.currentThread().sleep(5000); itemResult = client.getState(unlimitContract.getId()); System.out.println(">> state: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); for (int i = 0; i < main.config.getLimitRequestsForKeyPerMinute() * 2; i++) System.out.println(">> storage rate: " + client.storageGetRate()); for (int i = 0; i < main.config.getLimitRequestsForKeyPerMinute() * 2; i++) System.out.println(">> uns rate: " + client.unsRate()); for (int i = 0; i < main.config.getLimitRequestsForKeyPerMinute() * 2; i++) client.getStats(90); mm.forEach(x -> x.shutdown()); }
public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); static void main(String[] args); void waitReady(); void shutdown(); void setVerboseLevel(int level); void setUDPVerboseLevel(int level); void restartUDPAdapter(); PublicKey getNodePublicKey(); }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); static void main(String[] args); void waitReady(); void shutdown(); void setVerboseLevel(int level); void setUDPVerboseLevel(int level); void restartUDPAdapter(); PublicKey getNodePublicKey(); static final String NODE_VERSION; final Reporter reporter; final BufferedLogger logger; public NetConfig netConfig; public NetworkV2 network; final Config config; public NodeInfo myInfo; public Node node; public ItemCache cache; public ParcelCache parcelCache; public PaidOperationCache paidOperationCache; }