Skip to content

Commit

Permalink
use inner static class
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmao committed May 3, 2019
1 parent 9a52314 commit 6927479
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.github.ambry.replication.BlobIdTransformer;
import com.github.ambry.replication.MockConnectionPool;
import com.github.ambry.replication.MockFindToken;
import com.github.ambry.replication.MockFindTokenFactory;
import com.github.ambry.replication.MockHost;
import com.github.ambry.replication.RemoteReplicaInfo;
import com.github.ambry.replication.ReplicaThread;
Expand Down Expand Up @@ -355,7 +354,7 @@ public void testPutWithTtl() throws Exception {
replicationMetrics.populatePerColoMetrics(Collections.singleton(remoteHost.dataNodeId.getDatacenterName()));

ReplicaThread replicaThread =
new ReplicaThread("threadtest", replicasToReplicate, new MockFindTokenFactory(), clusterMap,
new ReplicaThread("threadtest", replicasToReplicate, new MockFindToken.MockFindTokenFactory(), clusterMap,
new AtomicInteger(0), cloudDataNode, connectionPool, replicationConfig, replicationMetrics, null,
storeKeyConverter, transformer, clusterMap.getMetricRegistry(), false, cloudDataNode.getDatacenterName(),
new ResponseHandler(clusterMap), new MockTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
*/
package com.github.ambry.replication;

import com.codahale.metrics.MetricRegistry;
import com.github.ambry.clustermap.ClusterMap;
import com.github.ambry.clustermap.DataNodeId;
import com.github.ambry.clustermap.MockPartitionId;
import com.github.ambry.clustermap.PartitionId;
import com.github.ambry.clustermap.ReplicaEventType;
import com.github.ambry.clustermap.ReplicaId;
import com.github.ambry.commons.BlobId;
import com.github.ambry.commons.BlobIdFactory;
import com.github.ambry.messageformat.BlobProperties;
Expand Down Expand Up @@ -46,6 +52,7 @@
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -502,8 +509,8 @@ private Message buildMessage(String blobIdString, Class clazz, boolean hasEncryp
int inputStreamSize;
MessageInfo messageInfo;
BlobProperties blobProperties =
new BlobProperties(blobPropertiesSize, "serviceId", "ownerId", "contentType", false, 0, 0, blobId.getAccountId(),
blobId.getContainerId(), hasEncryption, null);
new BlobProperties(blobPropertiesSize, "serviceId", "ownerId", "contentType", false, 0, 0,
blobId.getAccountId(), blobId.getContainerId(), hasEncryption, null);
if (clazz != null) {
MessageFormatInputStream messageFormatInputStream;
if (clazz == PutMessageFormatInputStream.class) {
Expand Down Expand Up @@ -562,4 +569,79 @@ private ByteBuffer createMetadataByteBuffer(String... datachunkIds) throws IOExc

private class BlobIdTransformerTestException extends Exception {
}

/**
* Mock clusterMap used when one wants the inputStream input for getPartitionIdFromStream
* to be read and have constructed a MockPartitionId from the input
*/
private class MockReadingClusterMap implements ClusterMap {
private boolean throwException = false;

public MockReadingClusterMap() {
}

public void setThrowException(boolean bool) {
this.throwException = bool;
}

public PartitionId getPartitionIdFromStream(InputStream inputStream) throws IOException {
if (this.throwException) {
throw new IOException();
} else {
byte[] bytes = new byte[10];
inputStream.read(bytes);
ByteBuffer bb = ByteBuffer.wrap(bytes);
bb.getShort();
long num = bb.getLong();
return new MockPartitionId(num, (String) null);
}
}

public List<? extends PartitionId> getWritablePartitionIds(String partitionClass) {
return null;
}

public List<? extends PartitionId> getAllPartitionIds(String partitionClass) {
return null;
}

public boolean hasDatacenter(String s) {
return false;
}

public byte getLocalDatacenterId() {
return 0;
}

public String getDatacenterName(byte b) {
return null;
}

public DataNodeId getDataNodeId(String s, int i) {
return null;
}

public List<? extends ReplicaId> getReplicaIds(DataNodeId dataNodeId) {
return null;
}

public List<? extends DataNodeId> getDataNodeIds() {
return null;
}

public MetricRegistry getMetricRegistry() {
return null;
}

public void onReplicaEvent(ReplicaId replicaId, ReplicaEventType replicaEventType) {
}

@Override
public JSONObject getSnapshot() {
return null;
}

public void close() {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/**
* A mock implementation of {@link Store} that store all details in memory.
*/
class MockStore implements Store {
class InMemoryStore implements Store {

class MockMessageReadSet implements MessageReadSet {

Expand Down Expand Up @@ -150,7 +150,7 @@ private void storeBuf(ByteBuffer buffer) {
final List<MessageInfo> messageInfos;
final PartitionId id;

MockStore(PartitionId id, List<MessageInfo> messageInfos, List<ByteBuffer> buffers,
InMemoryStore(PartitionId id, List<MessageInfo> messageInfos, List<ByteBuffer> buffers,
ReplicationTest.StoreEventListener listener) {
if (messageInfos.size() != buffers.size()) {
throw new IllegalArgumentException("message info size and buffer size does not match");
Expand Down

This file was deleted.

Loading

0 comments on commit 6927479

Please sign in to comment.