You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ed...@apache.org on 2021/09/06 21:31:36 UTC
[accumulo] branch wx930910-Refactor-MockRateLimiter created (now
df0e83d)
This is an automated email from the ASF dual-hosted git repository.
edcoleman pushed a change to branch wx930910-Refactor-MockRateLimiter
in repository https://gitbox.apache.org/repos/asf/accumulo.git.
at df0e83d Update PR with auto-format corrections
This branch includes the following new commits:
new 57fc7ba Merge branch 'Refactor-MockRateLimiter' of https://github.com/wx930910/accumulo into wx930910-Refactor-MockRateLimiter
new df0e83d Update PR with auto-format corrections
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[accumulo] 02/02: Update PR with auto-format corrections
Posted by ed...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
edcoleman pushed a commit to branch wx930910-Refactor-MockRateLimiter
in repository https://gitbox.apache.org/repos/asf/accumulo.git
commit df0e83dbf7eaa348f143abf0993a770120e4932a
Author: Ed Coleman <de...@etcoleman.com>
AuthorDate: Mon Sep 6 17:30:36 2021 -0400
Update PR with auto-format corrections
---
.../file/streams/RateLimitedInputStreamTest.java | 97 +++++++++++-----------
.../file/streams/RateLimitedOutputStreamTest.java | 58 ++++++-------
2 files changed, 79 insertions(+), 76 deletions(-)
diff --git a/core/src/test/java/org/apache/accumulo/core/file/streams/RateLimitedInputStreamTest.java b/core/src/test/java/org/apache/accumulo/core/file/streams/RateLimitedInputStreamTest.java
index aff7fbe..775a705 100644
--- a/core/src/test/java/org/apache/accumulo/core/file/streams/RateLimitedInputStreamTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/file/streams/RateLimitedInputStreamTest.java
@@ -32,60 +32,61 @@ import org.junit.Test;
public class RateLimitedInputStreamTest {
- @Test
- public void permitsAreProperlyAcquired() throws Exception {
- Random randGen = new SecureRandom();
- // Create variables for tracking behaviors of mock object
- AtomicLong rateLimiterPermitsAcquired = new AtomicLong();
- // Construct mock object
- RateLimiter rateLimiter = EasyMock.niceMock(RateLimiter.class);
- // Stub Mock Method
- rateLimiter.acquire(EasyMock.anyLong());
- EasyMock.expectLastCall().andAnswer(() -> rateLimiterPermitsAcquired.addAndGet(EasyMock.getCurrentArgument(0)))
- .anyTimes();
- EasyMock.replay(rateLimiter);
+ @Test
+ public void permitsAreProperlyAcquired() throws Exception {
+ Random randGen = new SecureRandom();
+ // Create variables for tracking behaviors of mock object
+ AtomicLong rateLimiterPermitsAcquired = new AtomicLong();
+ // Construct mock object
+ RateLimiter rateLimiter = EasyMock.niceMock(RateLimiter.class);
+ // Stub Mock Method
+ rateLimiter.acquire(EasyMock.anyLong());
+ EasyMock.expectLastCall()
+ .andAnswer(() -> rateLimiterPermitsAcquired.addAndGet(EasyMock.getCurrentArgument(0)))
+ .anyTimes();
+ EasyMock.replay(rateLimiter);
- long bytesRetrieved = 0;
- try (InputStream is = new RateLimitedInputStream(new RandomInputStream(), rateLimiter)) {
- for (int i = 0; i < 100; ++i) {
- int count = Math.abs(randGen.nextInt()) % 65536;
- int countRead = is.read(new byte[count]);
- assertEquals(count, countRead);
- bytesRetrieved += count;
- }
- }
- assertEquals(bytesRetrieved, rateLimiterPermitsAcquired.get());
- }
+ long bytesRetrieved = 0;
+ try (InputStream is = new RateLimitedInputStream(new RandomInputStream(), rateLimiter)) {
+ for (int i = 0; i < 100; ++i) {
+ int count = Math.abs(randGen.nextInt()) % 65536;
+ int countRead = is.read(new byte[count]);
+ assertEquals(count, countRead);
+ bytesRetrieved += count;
+ }
+ }
+ assertEquals(bytesRetrieved, rateLimiterPermitsAcquired.get());
+ }
- private static class RandomInputStream extends InputStream implements Seekable {
- private final Random r = new SecureRandom();
+ private static class RandomInputStream extends InputStream implements Seekable {
+ private final Random r = new SecureRandom();
- @Override
- public int read() {
- return r.nextInt() & 0xff;
- }
+ @Override
+ public int read() {
+ return r.nextInt() & 0xff;
+ }
- @Override
- public void seek(long pos) {
- throw new UnsupportedOperationException("Not supported yet."); // To change body of generated
- // methods, choose Tools |
- // Templates.
- }
+ @Override
+ public void seek(long pos) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated
+ // methods, choose Tools |
+ // Templates.
+ }
- @Override
- public long getPos() {
- throw new UnsupportedOperationException("Not supported yet."); // To change body of generated
- // methods, choose Tools |
- // Templates.
- }
+ @Override
+ public long getPos() {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated
+ // methods, choose Tools |
+ // Templates.
+ }
- @Override
- public boolean seekToNewSource(long targetPos) {
- throw new UnsupportedOperationException("Not supported yet."); // To change body of generated
- // methods, choose Tools |
- // Templates.
- }
+ @Override
+ public boolean seekToNewSource(long targetPos) {
+ throw new UnsupportedOperationException("Not supported yet."); // To change body of generated
+ // methods, choose Tools |
+ // Templates.
+ }
- }
+ }
}
diff --git a/core/src/test/java/org/apache/accumulo/core/file/streams/RateLimitedOutputStreamTest.java b/core/src/test/java/org/apache/accumulo/core/file/streams/RateLimitedOutputStreamTest.java
index ea81395..0472bae 100644
--- a/core/src/test/java/org/apache/accumulo/core/file/streams/RateLimitedOutputStreamTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/file/streams/RateLimitedOutputStreamTest.java
@@ -34,35 +34,37 @@ import com.google.common.io.CountingOutputStream;
public class RateLimitedOutputStreamTest {
- @Test
- public void permitsAreProperlyAcquired() throws Exception {
- Random randGen = new SecureRandom();
- // Create variables for tracking behaviors of mock object
- AtomicLong rateLimiterPermitsAcquired = new AtomicLong();
- // Construct mock object
- RateLimiter rateLimiter = EasyMock.niceMock(RateLimiter.class);
- // Stub Mock Method
- rateLimiter.acquire(EasyMock.anyLong());
- EasyMock.expectLastCall().andAnswer(() -> rateLimiterPermitsAcquired.addAndGet(EasyMock.getCurrentArgument(0)))
- .anyTimes();
- EasyMock.replay(rateLimiter);
+ @Test
+ public void permitsAreProperlyAcquired() throws Exception {
+ Random randGen = new SecureRandom();
+ // Create variables for tracking behaviors of mock object
+ AtomicLong rateLimiterPermitsAcquired = new AtomicLong();
+ // Construct mock object
+ RateLimiter rateLimiter = EasyMock.niceMock(RateLimiter.class);
+ // Stub Mock Method
+ rateLimiter.acquire(EasyMock.anyLong());
+ EasyMock.expectLastCall()
+ .andAnswer(() -> rateLimiterPermitsAcquired.addAndGet(EasyMock.getCurrentArgument(0)))
+ .anyTimes();
+ EasyMock.replay(rateLimiter);
- long bytesWritten = 0;
- try (RateLimitedOutputStream os = new RateLimitedOutputStream(new NullOutputStream(), rateLimiter)) {
- for (int i = 0; i < 100; ++i) {
- byte[] bytes = new byte[Math.abs(randGen.nextInt() % 65536)];
- os.write(bytes);
- bytesWritten += bytes.length;
- }
- assertEquals(bytesWritten, os.position());
- }
- assertEquals(bytesWritten, rateLimiterPermitsAcquired.get());
- }
+ long bytesWritten = 0;
+ try (RateLimitedOutputStream os =
+ new RateLimitedOutputStream(new NullOutputStream(), rateLimiter)) {
+ for (int i = 0; i < 100; ++i) {
+ byte[] bytes = new byte[Math.abs(randGen.nextInt() % 65536)];
+ os.write(bytes);
+ bytesWritten += bytes.length;
+ }
+ assertEquals(bytesWritten, os.position());
+ }
+ assertEquals(bytesWritten, rateLimiterPermitsAcquired.get());
+ }
- public static class NullOutputStream extends FSDataOutputStream {
- public NullOutputStream() {
- super(new CountingOutputStream(OutputStream.nullOutputStream()), null);
- }
- }
+ public static class NullOutputStream extends FSDataOutputStream {
+ public NullOutputStream() {
+ super(new CountingOutputStream(OutputStream.nullOutputStream()), null);
+ }
+ }
}
[accumulo] 01/02: Merge branch 'Refactor-MockRateLimiter' of
https://github.com/wx930910/accumulo into wx930910-Refactor-MockRateLimiter
Posted by ed...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
edcoleman pushed a commit to branch wx930910-Refactor-MockRateLimiter
in repository https://gitbox.apache.org/repos/asf/accumulo.git
commit 57fc7bab26f7392460e85a7526947b030478369c
Merge: 506f3c5 71aaea0
Author: Ed Coleman <de...@etcoleman.com>
AuthorDate: Mon Sep 6 17:15:24 2021 -0400
Merge branch 'Refactor-MockRateLimiter' of https://github.com/wx930910/accumulo into wx930910-Refactor-MockRateLimiter
.../core/file/streams/MockRateLimiter.java | 41 ----------
.../file/streams/RateLimitedInputStreamTest.java | 92 ++++++++++++----------
.../file/streams/RateLimitedOutputStreamTest.java | 55 +++++++------
3 files changed, 85 insertions(+), 103 deletions(-)