Skip to content

Commit

Permalink
remove redundant serialization test for JvmInfo and OsInfo and expand…
Browse files Browse the repository at this point in the history
… existing NodeInfoStreamingTests
  • Loading branch information
javanna committed Sep 2, 2016
1 parent e5a741a commit 746632f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static final class Fields {
* @param description Its description
* @param version Version number
*/
PluginInfo(String name, String description, String version, String classname) {
public PluginInfo(String name, String description, String version, String classname) {
this.name = name;
this.description = description;
this.version = version;
Expand Down
39 changes: 0 additions & 39 deletions core/src/test/java/org/elasticsearch/monitor/jvm/JvmInfoTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@

import org.apache.lucene.util.Constants;
import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.test.ESTestCase;

import java.io.IOException;

public class JvmInfoTests extends ESTestCase {

public void testUseG1GC() {
Expand Down Expand Up @@ -61,39 +57,4 @@ private boolean flagIsEnabled(String argline, String flag) {
final int index = argline.lastIndexOf(flag);
return argline.charAt(index - 1) == '+';
}

public void testSerialization() throws IOException {
JvmInfo jvmInfo = JvmInfo.jvmInfo();
try (BytesStreamOutput out = new BytesStreamOutput()) {
jvmInfo.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
JvmInfo deserializedJvmInfo = new JvmInfo(in);
assertEquals(jvmInfo.getVersion(), deserializedJvmInfo.getVersion());
assertEquals(jvmInfo.getVmName(), deserializedJvmInfo.getVmName());
assertEquals(jvmInfo.getVmVendor(), deserializedJvmInfo.getVmVendor());
assertEquals(jvmInfo.getVmVersion(), deserializedJvmInfo.getVmVersion());
assertEquals(jvmInfo.getBootClassPath(), deserializedJvmInfo.getBootClassPath());
assertEquals(jvmInfo.getClassPath(), deserializedJvmInfo.getClassPath());
assertEquals(jvmInfo.getPid(), deserializedJvmInfo.getPid());
assertEquals(jvmInfo.getStartTime(), deserializedJvmInfo.getStartTime());
assertEquals(jvmInfo.versionUpdatePack(), deserializedJvmInfo.versionUpdatePack());
assertEquals(jvmInfo.versionAsInteger(), deserializedJvmInfo.versionAsInteger());
assertEquals(jvmInfo.getMem().getDirectMemoryMax(), deserializedJvmInfo.getMem().getDirectMemoryMax());
assertEquals(jvmInfo.getMem().getHeapInit(), deserializedJvmInfo.getMem().getHeapInit());
assertEquals(jvmInfo.getMem().getHeapMax(), deserializedJvmInfo.getMem().getHeapMax());
assertEquals(jvmInfo.getMem().getNonHeapInit(), deserializedJvmInfo.getMem().getNonHeapInit());
assertEquals(jvmInfo.getMem().getNonHeapMax(), deserializedJvmInfo.getMem().getNonHeapMax());
assertEquals(jvmInfo.getSystemProperties(), deserializedJvmInfo.getSystemProperties());
assertArrayEquals(jvmInfo.getInputArguments(), deserializedJvmInfo.getInputArguments());
assertArrayEquals(jvmInfo.getGcCollectors(), deserializedJvmInfo.getGcCollectors());
assertArrayEquals(jvmInfo.getMemoryPools(), deserializedJvmInfo.getMemoryPools());
assertEquals(jvmInfo.useCompressedOops(), deserializedJvmInfo.useCompressedOops());
assertEquals(-1, deserializedJvmInfo.getConfiguredInitialHeapSize());
assertEquals(-1, deserializedJvmInfo.getConfiguredMaxHeapSize());
assertEquals("unknown", deserializedJvmInfo.useG1GC());
assertNull(deserializedJvmInfo.onError());
assertNull(deserializedJvmInfo.onOutOfMemoryError());
}
}
}
}
51 changes: 0 additions & 51 deletions core/src/test/java/org/elasticsearch/monitor/os/OsInfoTests.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.nodesinfo;

import org.elasticsearch.Build;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.cluster.node.DiscoveryNode;
Expand All @@ -35,11 +34,11 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.http.HttpInfo;
import org.elasticsearch.ingest.IngestInfo;
import org.elasticsearch.ingest.ProcessorInfo;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.monitor.os.DummyOsInfo;
import org.elasticsearch.monitor.os.OsInfo;
import org.elasticsearch.monitor.process.ProcessInfo;
import org.elasticsearch.plugins.DummyPluginInfo;
import org.elasticsearch.plugins.PluginInfo;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.threadpool.ThreadPool;
Expand All @@ -48,7 +47,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -58,23 +56,17 @@
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.core.IsEqual.equalTo;

/**
*
*/
public class NodeInfoStreamingTests extends ESTestCase {

public void testNodeInfoStreaming() throws IOException {
NodeInfo nodeInfo = createNodeInfo();
Version version = Version.CURRENT;
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(version);
nodeInfo.writeTo(out);
out.close();
StreamInput in = out.bytes().streamInput();
in.setVersion(version);
NodeInfo readNodeInfo = NodeInfo.readNodeInfo(in);
assertExpectedUnchanged(nodeInfo, readNodeInfo);

try (BytesStreamOutput out = new BytesStreamOutput()) {
nodeInfo.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
NodeInfo readNodeInfo = NodeInfo.readNodeInfo(in);
assertExpectedUnchanged(nodeInfo, readNodeInfo);
}
}
}
// checks all properties that are expected to be unchanged.
// Once we start changing them between versions this method has to be changed as well
Expand Down Expand Up @@ -126,22 +118,48 @@ private static NodeInfo createNodeInfo() {
DiscoveryNode node = new DiscoveryNode("test_node", LocalTransportAddress.buildUnique(),
emptyMap(), emptySet(), VersionUtils.randomVersion(random()));
Settings settings = Settings.builder().put("test", "setting").build();
OsInfo osInfo = DummyOsInfo.INSTANCE;
int availableProcessors = randomIntBetween(1, 64);
int allocatedProcessors = randomIntBetween(1, availableProcessors);
long refreshInterval = randomBoolean() ? -1 : randomPositiveLong();
String name = randomAsciiOfLengthBetween(3, 10);
String arch = randomAsciiOfLengthBetween(3, 10);
String version = randomAsciiOfLengthBetween(3, 10);
OsInfo osInfo = new OsInfo(refreshInterval, availableProcessors, allocatedProcessors, name, arch, version);
ProcessInfo process = new ProcessInfo(randomInt(), randomBoolean(), randomPositiveLong());
JvmInfo jvm = JvmInfo.jvmInfo();
List<ThreadPool.Info> threadPoolInfos = new ArrayList<>();
threadPoolInfos.add(new ThreadPool.Info("test_threadpool", ThreadPool.ThreadPoolType.FIXED, 5));
int numThreadPools = randomIntBetween(1, 10);
List<ThreadPool.Info> threadPoolInfos = new ArrayList<>(numThreadPools);
for (int i = 0; i < numThreadPools; i++) {
threadPoolInfos.add(new ThreadPool.Info(randomAsciiOfLengthBetween(3, 10),
randomFrom(ThreadPool.ThreadPoolType.values()), randomInt()));
}
ThreadPoolInfo threadPoolInfo = new ThreadPoolInfo(threadPoolInfos);
Map<String, BoundTransportAddress> profileAddresses = new HashMap<>();
BoundTransportAddress dummyBoundTransportAddress = new BoundTransportAddress(
new TransportAddress[]{LocalTransportAddress.buildUnique()}, LocalTransportAddress.buildUnique());
profileAddresses.put("test_address", dummyBoundTransportAddress);
TransportInfo transport = new TransportInfo(dummyBoundTransportAddress, profileAddresses);
HttpInfo htttpInfo = new HttpInfo(dummyBoundTransportAddress, randomLong());
HttpInfo httpInfo = new HttpInfo(dummyBoundTransportAddress, randomLong());

PluginsAndModules plugins = new PluginsAndModules(Collections.singletonList(DummyPluginInfo.INSTANCE),
Collections.singletonList(DummyPluginInfo.INSTANCE));
IngestInfo ingestInfo = new IngestInfo(Collections.emptyList());
int numPlugins = randomIntBetween(0, 5);
List<PluginInfo> plugins = new ArrayList<>();
for (int i = 0; i < numPlugins; i++) {
plugins.add(new PluginInfo(randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10),
randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10)));
}
int numModules = randomIntBetween(0, 5);
List<PluginInfo> modules = new ArrayList<>();
for (int i = 0; i < numModules; i++) {
modules.add(new PluginInfo(randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10),
randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10)));
}
PluginsAndModules pluginsAndModules = new PluginsAndModules(plugins, modules);
int numProcessors = randomIntBetween(0, 5);
List<ProcessorInfo> processors = new ArrayList<>(numProcessors);
for (int i = 0; i < numProcessors; i++) {
processors.add(new ProcessorInfo(randomAsciiOfLengthBetween(3, 10)));
}
IngestInfo ingestInfo = new IngestInfo(processors);
ByteSizeValue indexingBuffer;
if (random().nextBoolean()) {
indexingBuffer = null;
Expand All @@ -150,6 +168,6 @@ private static NodeInfo createNodeInfo() {
indexingBuffer = new ByteSizeValue(random().nextLong() & ((1L<<40)-1));
}
return new NodeInfo(VersionUtils.randomVersion(random()), build, node, settings, osInfo, process, jvm,
threadPoolInfo, transport, htttpInfo, plugins, ingestInfo, indexingBuffer);
threadPoolInfo, transport, httpInfo, pluginsAndModules, ingestInfo, indexingBuffer);
}
}

0 comments on commit 746632f

Please sign in to comment.