remove redundant serialization test for JvmInfo and OsInfo and expand existing NodeInfoStreamingTests
This commit is contained in:
parent
e5a741ab67
commit
746632fcf9
|
@ -57,7 +57,7 @@ public class PluginInfo implements Writeable, ToXContent {
|
|||
* @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;
|
||||
|
|
|
@ -21,12 +21,8 @@ package org.elasticsearch.monitor.jvm;
|
|||
|
||||
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() {
|
||||
|
@ -61,39 +57,4 @@ public class JvmInfoTests extends ESTestCase {
|
|||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.monitor.os;
|
||||
|
||||
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 OsInfoTests extends ESTestCase {
|
||||
|
||||
public void testSerialization() throws IOException {
|
||||
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);
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
osInfo.writeTo(out);
|
||||
try (StreamInput in = out.bytes().streamInput()) {
|
||||
OsInfo deserializedOsInfo = new OsInfo(in);
|
||||
assertEquals(osInfo.getRefreshInterval(), deserializedOsInfo.getRefreshInterval());
|
||||
assertEquals(osInfo.getAvailableProcessors(), deserializedOsInfo.getAvailableProcessors());
|
||||
assertEquals(osInfo.getAllocatedProcessors(), deserializedOsInfo.getAllocatedProcessors());
|
||||
assertEquals(osInfo.getName(), deserializedOsInfo.getName());
|
||||
assertEquals(osInfo.getArch(), deserializedOsInfo.getArch());
|
||||
assertEquals(osInfo.getVersion(), deserializedOsInfo.getVersion());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
@ -35,11 +34,11 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
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;
|
||||
|
@ -48,7 +47,6 @@ import org.elasticsearch.transport.TransportInfo;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -58,23 +56,17 @@ import static java.util.Collections.emptySet;
|
|||
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
|
||||
|
@ -126,22 +118,48 @@ public class NodeInfoStreamingTests extends ESTestCase {
|
|||
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;
|
||||
|
@ -150,6 +168,6 @@ public class NodeInfoStreamingTests extends ESTestCase {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue