Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit50c6fb6

Browse files
committed
[1.1.0]
QueueManager new constructor introducedApiRunner proper queue used for testsQueueManager#close as AutoClosableEtherScanApi as AutoClosableCI updatedTests API key exposed
1 parent5c71cac commit50c6fb6

File tree

8 files changed

+60
-15
lines changed

8 files changed

+60
-15
lines changed

‎.github/workflows/gradle.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ jobs:
3333

3434
-name:Test
3535
run:./gradlew test jacocoTestReport
36+
env:
37+
API_KEY:${{ secrets.API_KEY }}
38+
39+
-name:SonarQube
40+
run:./gradlew sonarqube
41+
env:
42+
GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}
43+
SONAR_TOKEN:${{ secrets.SONAR_TOKEN }}

‎src/main/java/io/api/etherscan/core/impl/EtherScanApi.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
* @author GoodforGod
2121
* @since 28.10.2018
2222
*/
23-
publicclassEtherScanApi {
23+
publicclassEtherScanApiimplementsAutoCloseable{
2424

2525
privatestaticfinalSupplier<IHttpExecutor>DEFAULT_SUPPLIER =HttpExecutor::new;
2626

2727
publicstaticfinalStringDEFAULT_KEY ="YourApiKeyToken";
2828

29+
privatefinalIQueueManagerqueueManager;
2930
privatefinalIAccountApiaccount;
3031
privatefinalIBlockApiblock;
3132
privatefinalIContractApicontract;
@@ -87,6 +88,7 @@ public EtherScanApi(final String apiKey,
8788
finalStringending =EthNetwork.TOBALABA.equals(network) ?"com" :"io";
8889
finalStringbaseUrl ="https://" +network.getDomain() +".etherscan." +ending +"/api" +"?apikey=" +apiKey;
8990

91+
this.queueManager =queue;
9092
this.account =newAccountApiProvider(queue,baseUrl,executor);
9193
this.block =newBlockApiProvider(queue,baseUrl,executor);
9294
this.contract =newContractApiProvider(queue,baseUrl,executor);
@@ -130,4 +132,9 @@ public IProxyApi proxy() {
130132
publicIStatisticApistats() {
131133
returnstats;
132134
}
135+
136+
@Override
137+
publicvoidclose()throwsException {
138+
queueManager.close();
139+
}
133140
}

‎src/main/java/io/api/etherscan/manager/IQueueManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author GoodforGod
88
* @since 30.10.2018
99
*/
10-
publicinterfaceIQueueManager {
10+
publicinterfaceIQueueManagerextendsAutoCloseable{
1111

1212
/**
1313
* Waits in queue for chance to take turn

‎src/main/java/io/api/etherscan/manager/impl/FakeQueueManager.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ public void takeTurn() {
1515
// no limit or await provided for fake impl so rate limit exception will be
1616
// thrown if too many calls
1717
}
18+
19+
@Override
20+
publicvoidclose() {
21+
// do nothing
22+
}
1823
}

‎src/main/java/io/api/etherscan/manager/impl/QueueManager.java‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,39 @@
1212
* @author GoodforGod
1313
* @since 30.10.2018
1414
*/
15-
publicclassQueueManagerimplementsIQueueManager {
15+
publicclassQueueManagerimplementsIQueueManager,AutoCloseable {
1616

1717
publicstaticfinalQueueManagerDEFAULT_KEY_QUEUE =newQueueManager(1,7);
18-
publicstaticfinalQueueManagerPERSONAL_KEY_QUEUE =newQueueManager(2,1);
18+
publicstaticfinalQueueManagerPERSONAL_KEY_QUEUE =newQueueManager(5,1100L,1100L,5);
1919

20+
privatefinalScheduledExecutorServiceexecutorService =Executors.newSingleThreadScheduledExecutor();
2021
privatefinalSemaphoresemaphore;
2122

2223
publicQueueManager(intsize,intresetInSec) {
2324
this(size,resetInSec,resetInSec);
2425
}
2526

2627
publicQueueManager(intsize,intqueueResetTimeInSec,intdelayInSec) {
27-
this.semaphore =newSemaphore(size);
28-
Executors.newSingleThreadScheduledExecutor()
29-
.scheduleAtFixedRate(releaseLocks(size),delayInSec,queueResetTimeInSec,TimeUnit.SECONDS);
28+
this(size,queueResetTimeInSec,delayInSec,size);
29+
}
30+
31+
publicQueueManager(intsize,
32+
intqueueResetTimeInSec,
33+
intdelayInSec,
34+
intinitialSize) {
35+
this(size,
36+
(long)queueResetTimeInSec *1000,
37+
(long)delayInSec *1000,
38+
initialSize);
39+
}
40+
41+
publicQueueManager(intsize,
42+
longqueueResetTimeInMillis,
43+
longdelayInMillis,
44+
intinitialSize) {
45+
this.semaphore =newSemaphore(initialSize);
46+
this.executorService.scheduleAtFixedRate(releaseLocks(size),delayInMillis,queueResetTimeInMillis,
47+
TimeUnit.MILLISECONDS);
3048
}
3149

3250
@Override
@@ -37,4 +55,9 @@ public void takeTurn() {
3755
privateRunnablereleaseLocks(inttoRelease) {
3856
return () ->semaphore.release(toRelease);
3957
}
58+
59+
@Override
60+
publicvoidclose() {
61+
executorService.shutdown();
62+
}
4063
}

‎src/test/java/io/api/ApiRunner.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
packageio.api;
22

33
importio.api.etherscan.core.impl.EtherScanApi;
4+
importio.api.etherscan.manager.impl.QueueManager;
45
importio.api.etherscan.model.EthNetwork;
56
importorg.junit.Assert;
67

@@ -18,10 +19,11 @@ public class ApiRunner extends Assert {
1819
?EtherScanApi.DEFAULT_KEY
1920
:apiKey;
2021

21-
api =newEtherScanApi(key,EthNetwork.MAINNET);
22-
apiRopsten =newEtherScanApi(key,EthNetwork.ROPSTEN);
23-
apiRinkeby =newEtherScanApi(key,EthNetwork.RINKEBY);
24-
apiKovan =newEtherScanApi(key,EthNetwork.KOVAN);
22+
finalQueueManagerqueueManager =newQueueManager(2,2100L,2100L,0);
23+
api =newEtherScanApi(key,EthNetwork.MAINNET,queueManager);
24+
apiKovan =newEtherScanApi(key,EthNetwork.KOVAN,queueManager);
25+
apiRopsten =newEtherScanApi(key,EthNetwork.ROPSTEN,queueManager);
26+
apiRinkeby =newEtherScanApi(key,EthNetwork.RINKEBY,queueManager);
2527
}
2628

2729
publicstaticStringgetKey() {

‎src/test/java/io/api/etherscan/proxy/ProxyCallApiTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public void correctParamWithEmptyExpectedResult() {
4141
Optional<String>call =getApi().proxy().call("0xAEEF16DB4855E25702F8237E8f403FddcaF931C0",
4242
"0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724");
4343
assertTrue(call.isPresent());
44-
assertFalse(BasicUtils.isNotHex(call.get()));
44+
assertFalse(call.get(),BasicUtils.isNotHex(call.get()));
4545
}
4646
}

‎src/test/java/io/api/etherscan/proxy/ProxyCodeApiTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ public class ProxyCodeApiTest extends ApiRunner {
1919
publicvoidcorrect() {
2020
Optional<String>call =getApi().proxy().code("0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c");
2121
assertTrue(call.isPresent());
22-
assertFalse(BasicUtils.isNotHex(call.get()));
22+
assertFalse(call.get(),BasicUtils.isNotHex(call.get()));
2323
}
2424

2525
@Test(expected =InvalidAddressException.class)
2626
publicvoidinvalidParamWithError() {
27-
Optional<String>call =getApi().proxy().code("0f75e354c5edc8efed9b59ee9f67a80845ade7d0c");
27+
getApi().proxy().code("0f75e354c5edc8efed9b59ee9f67a80845ade7d0c");
2828
}
2929

3030
@Test
3131
publicvoidcorrectParamWithEmptyExpectedResult() {
3232
Optional<String>call =getApi().proxy().code("0xf15e354c5edc8efed9b59ee9f67a80845ade7d0c");
3333
assertTrue(call.isPresent());
34-
assertFalse(BasicUtils.isNotHex(call.get()));
34+
assertFalse(call.get(),BasicUtils.isNotHex(call.get()));
3535
}
3636
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp