@Test public void checkLimitRequestsForKey() 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()); } for (int i = 0; i < main.config.getLimitRequestsForKeyPerMinute() * 2; i++) { Contract testContract = new Contract(myKey); testContract.seal(); assertTrue(testContract.isOk()); Set<PublicKey> ownerKeys = new HashSet(); Collection<PrivateKey> keys = Do.listOf(myKey); keys.stream().forEach(key -> ownerKeys.add(key.getPublicKey())); Contract stepaU = InnerContractsService.createFreshU(100000000, ownerKeys); stepaU.check(); stepaU.traceErrors(); client.register(stepaU.getPackedTransaction()); Set<PrivateKey> keySet = new HashSet<>(); keySet.addAll(keys); Parcel parcel = ContractsService.createParcel(testContract, stepaU, 150, keySet); client.registerParcel(parcel.pack()); } 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"); System.out.println("Wait 1 munite..."); Thread.currentThread().sleep(60000); seconds = ZonedDateTime.now().toEpochSecond() % 60; if (seconds > 57) Thread.currentThread().sleep(3000); for (int i = 0; i < main.config.getLimitRequestsForKeyPerMinute(); i++) System.out.println(">> uns rate: " + client.unsRate()); exception = ""; try { client.unsRate(); } 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"); System.out.println("Wait 1 munite..."); Thread.currentThread().sleep(60000); seconds = ZonedDateTime.now().toEpochSecond() % 60; if (seconds > 57) Thread.currentThread().sleep(3000); for (int i = 0; i < main.config.getLimitRequestsForKeyPerMinute(); i++) client.getStats(90); exception = ""; try { client.getStats(90); } 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"); 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; }