Skip to content

Commit

Permalink
Update after @javanna review
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrx committed Apr 22, 2015
1 parent b9d004b commit 2d8f854
Showing 1 changed file with 5 additions and 13 deletions.
Expand Up @@ -33,37 +33,29 @@

public class ClusterBlockTests extends ElasticsearchTestCase {

private static ClusterBlockLevel[] ALL_CLUSTER_BLOCK_LEVELS = ClusterBlockLevel.ALL.toArray(new ClusterBlockLevel[ALL.size()]);

@Test
public void testSerialization() throws Exception {
int iterations = randomIntBetween(5, 20);
for (int i = 0; i < iterations; i++) {
// Get a random version
Version fromVersion = randomVersion();
Version toVersion = randomVersion();

ClusterBlockLevel[] blockLevels = ALL_CLUSTER_BLOCK_LEVELS;
if (fromVersion.before(Version.V_1_6_0)) {
blockLevels = new ClusterBlockLevel[]{READ, WRITE, METADATA};
}
Version version = randomVersion();

// Get a random list of ClusterBlockLevels
EnumSet<ClusterBlockLevel> levels = EnumSet.noneOf(ClusterBlockLevel.class);
int nbLevels = randomIntBetween(1, blockLevels.length);
int nbLevels = randomIntBetween(1, ClusterBlockLevel.values().length);
for (int j = 0; j < nbLevels; j++) {
levels.add(randomFrom(blockLevels));
levels.add(randomFrom(ClusterBlockLevel.values()));
}

ClusterBlock clusterBlock = new ClusterBlock(randomInt(), "cluster block #" + randomInt(), randomBoolean(),
randomBoolean(), randomFrom(RestStatus.values()), levels);

BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(toVersion);
out.setVersion(version);
clusterBlock.writeTo(out);

BytesStreamInput in = new BytesStreamInput(out.bytes());
in.setVersion(toVersion);
in.setVersion(version);
ClusterBlock result = ClusterBlock.readClusterBlock(in);

assertThat(result.id(), equalTo(clusterBlock.id()));
Expand Down

0 comments on commit 2d8f854

Please sign in to comment.