Skip to content

Commit

Permalink
Merge pull request #2 from amplab/master
Browse files Browse the repository at this point in the history
[TACHYON-1287] Add Javadoc for start() in LeaderSelectorClient.java
  • Loading branch information
cybermaster committed Nov 14, 2015
2 parents 7385985 + 6dcdb76 commit 3b7da2a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void singleByteWriteTest() throws Exception {
// Test writing an increasing byte array one byte at a time
for (int i = 0; i < BLOCK_LENGTH; i ++) {
mTestStream.write(INCREASING_BYTES[i]);
Assert.assertEquals(i + 1, mTestStream.getBytesWritten());
Assert.assertEquals(i + 1, mTestStream.getWrittenBytes());
}
Assert.assertArrayEquals(INCREASING_BYTES,
Arrays.copyOfRange(mTestStream.getBuffer().array(), 0, (int) BLOCK_LENGTH));
Expand All @@ -68,7 +68,7 @@ public void singleByteWriteTest() throws Exception {
public void byteArrayWriteTest() throws Exception {
// Test writing an increasing byte array
mTestStream.write(INCREASING_BYTES);
Assert.assertEquals(INCREASING_BYTES.length, mTestStream.getBytesWritten());
Assert.assertEquals(INCREASING_BYTES.length, mTestStream.getWrittenBytes());
Assert.assertArrayEquals(INCREASING_BYTES,
Arrays.copyOfRange(mTestStream.getBuffer().array(), 0, (int) BLOCK_LENGTH));
}
Expand All @@ -77,7 +77,7 @@ public void byteArrayWriteTest() throws Exception {
public void byteArrayAtOffsetTest() throws Exception {
// Test writing the middle half of an increasing byte array
mTestStream.write(INCREASING_BYTES, 25, 50);
Assert.assertEquals(50, mTestStream.getBytesWritten());
Assert.assertEquals(50, mTestStream.getWrittenBytes());
Assert.assertArrayEquals(BufferUtils.getIncreasingByteArray(25, 50),
Arrays.copyOfRange(mTestStream.getBuffer().array(), 0, 50));

Expand All @@ -89,7 +89,7 @@ public void byteArrayAtOffsetTest() throws Exception {
Assert.assertSame(INCREASING_BYTES, mTestStream.mLastBufferedWriteArray);
Assert.assertEquals(30, mTestStream.mLastBufferedWriteOffset);
Assert.assertEquals(bytesToWrite, mTestStream.mLastBufferedWriteLen);
Assert.assertEquals(50 + mTestStream.mLastBufferedWriteLen, mTestStream.getBytesWritten());
Assert.assertEquals(50 + mTestStream.mLastBufferedWriteLen, mTestStream.getWrittenBytes());
}

@Test
Expand All @@ -107,4 +107,14 @@ public void writePastBlock() throws Exception {
mThrown.expectMessage(PreconditionMessage.ERR_END_OF_BLOCK);
mTestStream.write(0);
}

@Test
public void doubleFlush() throws Exception {
mTestStream.write(INCREASING_BYTES, 1, 10);
Assert.assertEquals(0, mTestStream.getFlushedBytes());
mTestStream.flush();
Assert.assertEquals(10, mTestStream.getFlushedBytes());
mTestStream.flush();
Assert.assertEquals(10, mTestStream.getFlushedBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TestBufferedBlockOutStream(long blockId, long blockSize) {
/**
* @return all data which has even been written through the stream via write()
*/
public byte[] getDataWritten() {
public byte[] getWrittenData() {
flush();
return Arrays.copyOfRange(mDataWritten.array(), 0, (int) mWrittenBytes);
}
Expand All @@ -51,10 +51,14 @@ public void setWrittenBytes(long numBytes) {
mWrittenBytes = numBytes;
}

public int getBytesWritten() {
public int getWrittenBytes() {
return (int) mWrittenBytes;
}

public int getFlushedBytes() {
return (int) mFlushedBytes;
}

public ByteBuffer getBuffer() {
return mBuffer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void testSeek() throws IOException {
Assert.assertTrue(mCacheStreams.get(0).isCanceled());
Assert.assertArrayEquals(
BufferUtils.getIncreasingByteArray((int) BLOCK_LENGTH, (int) BLOCK_LENGTH),
mCacheStreams.get(1).getDataWritten());
mCacheStreams.get(1).getWrittenData());

// Seek to current position (does nothing)
mTestStream.seek(seekAmount + readAmount);
Expand All @@ -241,7 +241,7 @@ public void testSkip() throws IOException {
Assert.assertTrue(mCacheStreams.get(0).isCanceled());
Assert.assertArrayEquals(
BufferUtils.getIncreasingByteArray((int) BLOCK_LENGTH, (int) BLOCK_LENGTH),
mCacheStreams.get(1).getDataWritten());
mCacheStreams.get(1).getWrittenData());

Assert.assertEquals(0, mTestStream.skip(0));
// Skip the next half block, bringing us to block 3
Expand Down Expand Up @@ -394,7 +394,7 @@ private void testReadBuffer(int dataRead) throws Exception {
private void verifyCacheStreams(long dataRead) {
for (int streamIndex = 0; streamIndex < NUM_STREAMS; streamIndex ++) {
TestBufferedBlockOutStream stream = mCacheStreams.get(streamIndex);
byte[] data = stream.getDataWritten();
byte[] data = stream.getWrittenData();
if (streamIndex * BLOCK_LENGTH > dataRead) {
Assert.assertEquals(0, data.length);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void flush() {
@Test
public void singleByteWriteTest() throws Exception {
mTestStream.write(5);
Assert.assertArrayEquals(new byte[] {5}, mTachyonOutStreamMap.get(0L).getDataWritten());
Assert.assertArrayEquals(new byte[] {5}, mTachyonOutStreamMap.get(0L).getWrittenData());
}

/**
Expand Down Expand Up @@ -328,13 +328,13 @@ private void verifyIncreasingBytesWritten(int start, int len) {
mTachyonOutStreamMap.containsKey(streamIndex));
Assert.assertArrayEquals(BufferUtils
.getIncreasingByteArray((int) (streamIndex * BLOCK_LENGTH + start), (int) BLOCK_LENGTH),
mTachyonOutStreamMap.get(streamIndex).getDataWritten());
mTachyonOutStreamMap.get(streamIndex).getWrittenData());
}
long lastStreamBytes = len - filledStreams * BLOCK_LENGTH;
Assert.assertArrayEquals(
BufferUtils.getIncreasingByteArray((int) (filledStreams * BLOCK_LENGTH + start),
(int) lastStreamBytes),
mTachyonOutStreamMap.get(filledStreams).getDataWritten());
mTachyonOutStreamMap.get(filledStreams).getWrittenData());

Assert.assertArrayEquals(BufferUtils.getIncreasingByteArray(start, len),
mUnderStorageOutputStream.toByteArray());
Expand Down
1 change: 1 addition & 0 deletions servers/src/main/java/tachyon/ValidateConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ public static void main(String[] args) {
System.exit(0);
}

private ValidateConf() {} // prevent instantiation.
}
18 changes: 18 additions & 0 deletions servers/src/main/java/tachyon/web/WebInterfaceWorkersServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.common.base.Objects;

import tachyon.Constants;
import tachyon.conf.TachyonConf;
import tachyon.master.block.BlockMaster;
Expand Down Expand Up @@ -112,6 +114,22 @@ public int compareTo(NodeInfo o) {
return this.getHost().compareTo(o.getHost());
}
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof NodeInfo)) {
return false;
}
return this.getHost().equals(((NodeInfo) o).getHost());
}

@Override
public int hashCode() {
return Objects.hashCode(this.getHost());
}
}

private static final long serialVersionUID = -7454493761603179826L;
Expand Down

0 comments on commit 3b7da2a

Please sign in to comment.