Skip to content

Commit ea512d1

Browse files
committed
[1.1.0-SNAPSHOT]
FailFast true added [1.1.0-SNAPSHOT] Only java 11 for testing is left [1.1.0-SNAPSHOT] Tests on push disabled for RateLimit not exceed [1.1.0-SNAPSHOT] CI api key env setted [1.1.0-SNAPSHOT] QueueManager 7 sec instead of 6 set [1.1.0-SNAPSHOT] Test fixed with correct address for ABI Debug logging removed PersonalQueue optimized [1.1.0-SNAPSHOT] Key removed [1.1.0-SNAPSHOT] Weak queue set for tests [1.1.0-SNAPSHOT] Rest before timeout check for api not exceed rate
1 parent af94534 commit ea512d1

File tree

7 files changed

+32
-34
lines changed

7 files changed

+32
-34
lines changed

.github/workflows/gradle.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: Java CI
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
- dev
84
schedule:
95
- cron: "0 12 1 * *"
106
pull_request:
@@ -17,7 +13,7 @@ jobs:
1713
runs-on: ubuntu-latest
1814
strategy:
1915
matrix:
20-
java: [ '1.8', '11' ]
16+
java: [ '11' ]
2117
name: Java ${{ matrix.java }} setup
2218

2319
steps:
@@ -30,9 +26,12 @@ jobs:
3026

3127
- name: Build with Gradle
3228
run: ./gradlew build jacocoTestReport
29+
env:
30+
API_KEY: ${{ secrets.API_KEY }}
3331

3432
- name: Analyze with SonarQube
3533
run: ./gradlew sonarqube
3634
env:
3735
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3836
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37+
API_KEY: ${{ secrets.API_KEY }}

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ dependencies {
4343
}
4444

4545
test {
46+
failFast = true
47+
4648
useJUnit()
4749
testLogging {
4850
events "passed", "skipped", "failed"

src/main/java/io/api/etherscan/core/impl/BasicProvider.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
import io.api.etherscan.error.RateLimitException;
88
import io.api.etherscan.executor.IHttpExecutor;
99
import io.api.etherscan.manager.IQueueManager;
10-
import io.api.etherscan.manager.impl.QueueManager;
1110
import io.api.etherscan.model.utility.StringResponseTO;
1211
import io.api.etherscan.util.BasicUtils;
1312

14-
import java.time.LocalTime;
1513
import java.util.Map;
16-
import java.util.logging.Level;
17-
import java.util.logging.Logger;
1814

1915
/**
2016
* Base provider for API Implementations
@@ -25,8 +21,6 @@
2521
*/
2622
abstract class BasicProvider {
2723

28-
private static final Logger logger = Logger.getLogger(QueueManager.class.getName());
29-
3024
static final int MAX_END_BLOCK = Integer.MAX_VALUE;
3125
static final int MIN_START_BLOCK = 0;
3226

@@ -76,9 +70,7 @@ <T> T convert(final String json, final Class<T> tClass) {
7670
}
7771

7872
String getRequest(final String urlParameters) {
79-
logger.log(Level.SEVERE, "ASKED - " + LocalTime.now());
8073
queue.takeTurn();
81-
logger.log(Level.SEVERE, "GRANTED - " + LocalTime.now());
8274
final String url = baseUrl + module + urlParameters;
8375
final String result = executor.get(url);
8476
if (BasicUtils.isEmpty(result))
@@ -88,9 +80,7 @@ String getRequest(final String urlParameters) {
8880
}
8981

9082
String postRequest(final String urlParameters, final String dataToPost) {
91-
logger.log(Level.SEVERE, "ASKED - " + LocalTime.now());
9283
queue.takeTurn();
93-
logger.log(Level.SEVERE, "GRANTED - " + LocalTime.now());
9484
final String url = baseUrl + module + urlParameters;
9585
return executor.post(url, dataToPost);
9686
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.concurrent.*;
66

77
/**
8-
* Queue implementation With size and reset time as params
8+
* Queue Semaphore implementation with size and reset time as params
99
*
1010
* @see IQueueManager
1111
*
@@ -14,19 +14,19 @@
1414
*/
1515
public class QueueManager implements IQueueManager {
1616

17-
public static final QueueManager DEFAULT_KEY_QUEUE = new QueueManager(1, 6);
18-
public static final QueueManager PERSONAL_KEY_QUEUE = new QueueManager(5, 1);
17+
public static final QueueManager DEFAULT_KEY_QUEUE = new QueueManager(1, 7);
18+
public static final QueueManager PERSONAL_KEY_QUEUE = new QueueManager(2, 1);
1919

2020
private final Semaphore semaphore;
2121

22-
public QueueManager(int queueSize, int queueResetTimeInSec) {
23-
this(queueSize, queueResetTimeInSec, queueResetTimeInSec);
22+
public QueueManager(int size, int resetInSec) {
23+
this(size, resetInSec, resetInSec);
2424
}
2525

26-
public QueueManager(int queueSize, int queueResetTimeInSec, int delayInSec) {
27-
this.semaphore = new Semaphore(queueSize);
26+
public QueueManager(int size, int queueResetTimeInSec, int delayInSec) {
27+
this.semaphore = new Semaphore(size);
2828
Executors.newSingleThreadScheduledExecutor()
29-
.scheduleAtFixedRate(releaseLocks(queueSize), delayInSec, queueResetTimeInSec, TimeUnit.SECONDS);
29+
.scheduleAtFixedRate(releaseLocks(size), delayInSec, queueResetTimeInSec, TimeUnit.SECONDS);
3030
}
3131

3232
@Override

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ public class ApiRunner extends Assert {
1111
private static final EtherScanApi apiRopsten;
1212
private static final EtherScanApi apiRinkeby;
1313
private static final EtherScanApi apiKovan;
14+
private static final String key;
1415

1516
static {
1617
final String apiKey = System.getenv("API_KEY");
17-
final String keyOrDefault = (apiKey == null || apiKey.isEmpty())
18+
key = (apiKey == null || apiKey.isEmpty())
1819
? EtherScanApi.DEFAULT_KEY
1920
: apiKey;
2021

21-
final QueueManager queue = keyOrDefault.equals(EtherScanApi.DEFAULT_KEY)
22+
final QueueManager queue = key.equals(EtherScanApi.DEFAULT_KEY)
2223
? QueueManager.DEFAULT_KEY_QUEUE
23-
: QueueManager.PERSONAL_KEY_QUEUE;
24+
: new QueueManager(1, 2);
2425

25-
api = new EtherScanApi(keyOrDefault, EthNetwork.MAINNET, queue);
26-
apiRopsten = new EtherScanApi(keyOrDefault, EthNetwork.ROPSTEN, queue);
27-
apiRinkeby = new EtherScanApi(keyOrDefault, EthNetwork.RINKEBY, queue);
28-
apiKovan = new EtherScanApi(keyOrDefault, EthNetwork.KOVAN, queue);
26+
api = new EtherScanApi(key, EthNetwork.MAINNET, queue);
27+
apiRopsten = new EtherScanApi(key, EthNetwork.ROPSTEN, queue);
28+
apiRinkeby = new EtherScanApi(key, EthNetwork.RINKEBY, queue);
29+
apiKovan = new EtherScanApi(key, EthNetwork.KOVAN, queue);
30+
}
31+
32+
public static String getKey() {
33+
return key;
2934
}
3035

3136
public static EtherScanApi getApi() {

src/test/java/io/api/etherscan/EtherScanApiTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.junit.Test;
1414

1515
import java.util.List;
16+
import java.util.concurrent.TimeUnit;
1617
import java.util.function.Supplier;
1718

1819
/**
@@ -75,9 +76,10 @@ public void noTimeoutUnlimitedAwait() {
7576
}
7677

7778
@Test(expected = ApiTimeoutException.class)
78-
public void timeout() {
79+
public void timeout() throws InterruptedException {
80+
TimeUnit.SECONDS.sleep(5);
7981
Supplier<IHttpExecutor> supplier = () -> new HttpExecutor(300, 300);
80-
EtherScanApi api = new EtherScanApi(EthNetwork.KOVAN, supplier);
82+
EtherScanApi api = new EtherScanApi(getKey(), EthNetwork.KOVAN, supplier);
8183
List<Block> blocks = api.account().minedBlocks("0x0010f94b296A852aAac52EA6c5Ac72e03afD032D");
8284
assertNotNull(blocks);
8385
}

src/test/java/io/api/etherscan/contract/ContractApiTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public void invalidParamWithError() {
3434

3535
@Test
3636
public void correctParamWithEmptyExpectedResult() {
37-
Abi abi = getApi().contract().contractAbi("0xBB1bc244D798123fDe783fCc1C72d3Bb8C189413");
37+
Abi abi = getApi().contract().contractAbi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413");
3838
assertNotNull(abi);
39-
assertFalse(abi.isVerified());
39+
assertTrue(abi.isVerified());
4040
}
4141
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy