Skip to content

Commit

Permalink
added missing serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvg committed Jun 19, 2018
1 parent a8abf0f commit 50ce990
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class CreateAndFollowIndexAction extends Action<CreateAndFollowIndexAction.Request, CreateAndFollowIndexAction.Response> {

Expand Down Expand Up @@ -89,6 +90,19 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
followRequest.writeTo(out);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Request request = (Request) o;
return Objects.equals(followRequest, request.followRequest);
}

@Override
public int hashCode() {
return Objects.hash(followRequest);
}
}

public static class Response extends ActionResponse implements ToXContentObject {
Expand Down Expand Up @@ -145,6 +159,21 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.endObject();
return builder;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Response response = (Response) o;
return followIndexCreated == response.followIndexCreated &&
followIndexShardsAcked == response.followIndexShardsAcked &&
indexFollowingStarted == response.indexFollowingStarted;
}

@Override
public int hashCode() {
return Objects.hash(followIndexCreated, followIndexShardsAcked, indexFollowingStarted);
}
}

public static class TransportAction extends TransportMasterNodeAction<Request, Response> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;
Expand Down Expand Up @@ -127,6 +128,7 @@ public void readFrom(StreamInput in) throws IOException {
leaderIndex = in.readString();
followIndex = in.readString();
batchSize = in.readVLong();
concurrentProcessors = in.readVInt();
processorMaxTranslogBytes = in.readVLong();
}

Expand All @@ -136,8 +138,26 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(leaderIndex);
out.writeString(followIndex);
out.writeVLong(batchSize);
out.writeVInt(concurrentProcessors);
out.writeVLong(processorMaxTranslogBytes);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Request request = (Request) o;
return batchSize == request.batchSize &&
concurrentProcessors == request.concurrentProcessors &&
processorMaxTranslogBytes == request.processorMaxTranslogBytes &&
Objects.equals(leaderIndex, request.leaderIndex) &&
Objects.equals(followIndex, request.followIndex);
}

@Override
public int hashCode() {
return Objects.hash(leaderIndex, followIndex, batchSize, concurrentProcessors, processorMaxTranslogBytes);
}
}

public static class Response extends AcknowledgedResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.ccr.action;

import org.elasticsearch.test.AbstractStreamableTestCase;

public class CreateAndFollowIndexRequestTests extends AbstractStreamableTestCase<CreateAndFollowIndexAction.Request> {

@Override
protected CreateAndFollowIndexAction.Request createBlankInstance() {
return new CreateAndFollowIndexAction.Request();
}

@Override
protected CreateAndFollowIndexAction.Request createTestInstance() {
CreateAndFollowIndexAction.Request request = new CreateAndFollowIndexAction.Request();
request.setFollowRequest(FollowIndexRequestTests.createTestRequest());
return request;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.ccr.action;

import org.elasticsearch.test.AbstractStreamableTestCase;

public class CreateAndFollowIndexResponseTests extends AbstractStreamableTestCase<CreateAndFollowIndexAction.Response> {

@Override
protected CreateAndFollowIndexAction.Response createBlankInstance() {
return new CreateAndFollowIndexAction.Response();
}

@Override
protected CreateAndFollowIndexAction.Response createTestInstance() {
return new CreateAndFollowIndexAction.Response(randomBoolean(), randomBoolean(), randomBoolean());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.ccr.action;

import org.elasticsearch.test.AbstractStreamableTestCase;

public class FollowIndexRequestTests extends AbstractStreamableTestCase<FollowIndexAction.Request> {

@Override
protected FollowIndexAction.Request createBlankInstance() {
return new FollowIndexAction.Request();
}

@Override
protected FollowIndexAction.Request createTestInstance() {
return createTestRequest();
}

static FollowIndexAction.Request createTestRequest() {
FollowIndexAction.Request request = new FollowIndexAction.Request();
request.setLeaderIndex(randomAlphaOfLength(4));
request.setFollowIndex(randomAlphaOfLength(4));
request.setBatchSize(randomNonNegativeLong());
request.setConcurrentProcessors(randomIntBetween(0, Integer.MAX_VALUE));
request.setProcessorMaxTranslogBytes(randomNonNegativeLong());
return request;
}
}

0 comments on commit 50ce990

Please sign in to comment.