Mercurial > hg > thermostat-ng > agent
changeset 2671:44da582cd062
Add TypeAdapters for the Threads plugin.
Reviewed-by: ebaron
Review-Thread: http://icedtea.classpath.org/pipermail/thermostat/2017-May/023243.html
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/internal/LockInfoTypeAdapter.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,132 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.redhat.thermostat.thread.model.LockInfo; + +import java.io.IOException; + +public class LockInfoTypeAdapter extends TypeAdapter<LockInfo> { + + private static final String TIMESTAMP = "timeStamp"; + private static final String TYPE_LONG = "$numberLong"; + private static final String VM_ID = "vmId"; + private static final String AGENT_ID = "agentId"; + private static final String CONTENDED_ATTEMPTS = "contendedLockAttempts"; + private static final String DEFLATIONS = "deflations"; + private static final String EMPTY_NOTIFICATIONS = "emptyNotifications"; + private static final String FAILED_SPINS = "failedSpins"; + private static final String FUTILE_WAKEUPS = "futileWakeups"; + private static final String INFLATIONS = "inflations"; + private static final String EXTANT_MONITORS = "monExtant"; + private static final String MON_IN_CIRCULATION = "monInCirculation"; + private static final String SCAVENGED_MONITORS = "monScavenged"; + private static final String NOTIFICATIONS = "notifications"; + private static final String PARKS = "parks"; + private static final String PRIVATE_A = "privateA"; + private static final String PRIVATE_B = "privateB"; + private static final String SLOW_ENTER = "slowEnter"; + private static final String SLOW_EXIT = "slowExit"; + private static final String SLOW_NOTIFY = "slowNotify"; + private static final String SLOW_NOTIFY_ALL = "slowNotifyAll"; + private static final String SUCCESSFUL_SPINS = "successfulSpins"; + + + @Override + public void write(JsonWriter out, LockInfo info) throws IOException { + out.beginObject(); + out.name(AGENT_ID); + out.value(info.getAgentId()); + out.name(VM_ID); + out.value(info.getVmId()); + out.name(TIMESTAMP); + writeLong(out, info.getTimeStamp()); + out.name(CONTENDED_ATTEMPTS); + writeLong(out, info.getContendedLockAttempts()); + out.name(DEFLATIONS); + writeLong(out, info.getDeflations()); + out.name(EMPTY_NOTIFICATIONS); + writeLong(out, info.getEmptyNotifications()); + out.name(FAILED_SPINS); + writeLong(out, info.getFailedSpins()); + out.name(FUTILE_WAKEUPS); + writeLong(out, info.getFutileWakeups()); + out.name(INFLATIONS); + writeLong(out, info.getInflations()); + out.name(EXTANT_MONITORS); + writeLong(out, info.getMonExtant()); + out.name(MON_IN_CIRCULATION); + writeLong(out, info.getMonInCirculation()); + out.name(SCAVENGED_MONITORS); + writeLong(out, info.getMonScavenged()); + out.name(NOTIFICATIONS); + writeLong(out, info.getNotifications()); + out.name(PARKS); + writeLong(out, info.getParks()); + out.name(PRIVATE_A); + writeLong(out, info.getPrivateA()); + out.name(PRIVATE_B); + writeLong(out, info.getPrivateB()); + out.name(SLOW_ENTER); + writeLong(out, info.getSlowEnter()); + out.name(SLOW_EXIT); + writeLong(out, info.getSlowExit()); + out.name(SLOW_NOTIFY); + writeLong(out, info.getSlowNotify()); + out.name(SLOW_NOTIFY_ALL); + writeLong(out, info.getSlowNotifyAll()); + out.name(SUCCESSFUL_SPINS); + writeLong(out, info.getSuccessfulSpins()); + out.endObject(); + } + + @Override + public LockInfo read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + private void writeLong(JsonWriter out, long value) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/internal/ThreadHarvestingStatusTypeAdapter.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.redhat.thermostat.thread.model.ThreadHarvestingStatus; + +import java.io.IOException; + +public class ThreadHarvestingStatusTypeAdapter extends TypeAdapter<ThreadHarvestingStatus> { + + private static final String TYPE_LONG = "$numberLong"; + private static final String AGENT_ID = "agentId"; + private static final String VM_ID = "vmId"; + private static final String TIMESTAMP = "timeStamp"; + private static final String COLLECTING = "collecting"; + + @Override + public void write(JsonWriter out, ThreadHarvestingStatus status) throws IOException { + out.beginObject(); + out.name(AGENT_ID); + out.value(status.getAgentId()); + out.name(VM_ID); + out.value(status.getVmId()); + out.name(TIMESTAMP); + writeLong(out, status.getTimeStamp()); + out.name(COLLECTING); + out.value(status.isHarvesting()); + out.endObject(); + } + + @Override + public ThreadHarvestingStatus read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + public void writeLong(JsonWriter out, long value) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/internal/ThreadSessionTypeAdapter.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,89 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.redhat.thermostat.thread.model.ThreadSession; + +import java.io.IOException; + +public class ThreadSessionTypeAdapter extends TypeAdapter<ThreadSession> { + + private static final String VM_ID = "vmId"; + private static final String AGENT_ID = "agentId"; + private static final String TIMESTAMP = "timeStamp"; + private static final String SESSION = "session"; + private static final String SESSION_ID = "sessionID"; + private static final String TYPE_LONG = "$numberLong"; + private static final String ID = "id"; + + + @Override + public void write(JsonWriter out, ThreadSession session) throws IOException { + out.beginObject(); + out.name(AGENT_ID); + out.value(session.getAgentId()); + out.name(VM_ID); + out.value(session.getVmId()); + out.name(TIMESTAMP); + writeLong(out, session.getTimeStamp()); + out.name(SESSION); + out.value(session.getSession()); + out.name(SESSION_ID); + out.beginObject(); + out.name(ID); + out.value(session.getSessionID().get()); + out.endObject(); + out.endObject(); + } + + @Override + public ThreadSession read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + private void writeLong(JsonWriter out, long value) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/internal/ThreadStateTypeAdapter.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,107 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.redhat.thermostat.thread.model.ThreadState; + +import java.io.IOException; + +public class ThreadStateTypeAdapter extends TypeAdapter<ThreadState> { + + private static final String AGENT_ID = "agentId"; + private static final String VM_ID = "vmId"; + private static final String NAME = "name"; + private static final String STATE = "state"; + private static final String SESSION = "session"; + private static final String ID = "id"; + private static final String SUSPENDED = "suspended"; + private static final String IN_NATIVE = "inNative"; + private static final String BLOCKED_COUNT = "blockedCount"; + private static final String BLOCKED_TIME = "blockedTime"; + private static final String WAITED_COUNT = "waitedCount"; + private static final String WAITED_TIME = "waitedTime"; + private static final String STACKTRACE = "stackTrace"; + private static final String TYPE_LONG = "$numberLong"; + + @Override + public ThreadState read(JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(JsonWriter out, ThreadState state) throws IOException { + out.beginObject(); + out.name(AGENT_ID); + out.value(state.getAgentId()); + out.name(VM_ID); + out.value(state.getVmId()); + out.name(NAME); + out.value(state.getName()); + out.name(STATE); + out.value(state.getState()); + out.name(SESSION); + out.value(state.getSession()); + out.name(ID); + writeLong(out, state.getId()); + out.name(SUSPENDED); + out.value(state.isSuspended()); + out.name(IN_NATIVE); + out.value(state.isInNative()); + out.name(BLOCKED_COUNT); + writeLong(out, state.getBlockedCount()); + out.name(BLOCKED_TIME); + writeLong(out, state.getBlockedTime()); + out.name(WAITED_COUNT); + writeLong(out, state.getWaitedCount()); + out.name(WAITED_TIME); + writeLong(out, state.getWaitedTime()); + out.name(STACKTRACE); + out.value(state.getStackTrace()); + out.endObject(); + } + + private void writeLong(JsonWriter out, long value) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/internal/ThreadSummaryTypeAdapter.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,83 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.redhat.thermostat.thread.model.ThreadSummary; + +import java.io.IOException; + +public class ThreadSummaryTypeAdapter extends TypeAdapter<ThreadSummary> { + + private static final String VM_ID = "vmId"; + private static final String AGENT_ID = "agentId"; + private static final String TIMESTAMP = "timeStamp"; + private static final String LIVE_THREADS = "currentLiveThreads"; + private static final String DAEMON_THREADS = "daemonThreads"; + private static final String TYPE_LONG = "$numberLong"; + + @Override + public ThreadSummary read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void write(JsonWriter out, ThreadSummary t) throws IOException { + out.beginObject(); + out.name(AGENT_ID); + out.value(t.getAgentId()); + out.name(VM_ID); + out.value(t.getVmId()); + out.name(TIMESTAMP); + writeLong(out, t.getTimeStamp()); + out.name(LIVE_THREADS); + writeLong(out, t.getCurrentLiveThreads()); + out.name(DAEMON_THREADS); + writeLong(out, t.getCurrentDaemonThreads()); + out.endObject(); + } + + private void writeLong(JsonWriter out, long value) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/internal/VmDeadLockDataTypeAdapter.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.redhat.thermostat.thread.model.VmDeadLockData; + +import java.io.IOException; + +public class VmDeadLockDataTypeAdapter extends TypeAdapter<VmDeadLockData> { + + private static final String TIMESTAMP = "timeStamp"; + private static final String VM_ID = "vmId"; + private static final String AGENT_ID = "agentId"; + private static final String DESCRIPTION = "description"; + private static final String TYPE_LONG = "$numberLong"; + + @Override + public void write(JsonWriter out, VmDeadLockData data) throws IOException { + out.beginObject(); + out.name(AGENT_ID); + out.value(data.getAgentId()); + out.name(VM_ID); + out.value(data.getVmId()); + out.name(TIMESTAMP); + writeLong(out, data.getTimeStamp()); + out.name(DESCRIPTION); + out.value(data.getDeadLockDescription()); + out.endObject(); + } + + @Override + public VmDeadLockData read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + private void writeLong(JsonWriter out, long value) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/internal/LockInfoTypeAdapterTest.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,56 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.redhat.thermostat.thread.model.LockInfo; +import org.junit.Assert; +import org.junit.Test; + +public class LockInfoTypeAdapterTest { + + @Test + public void testWrite() { + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(LockInfo.class, new LockInfoTypeAdapter()); + Gson gson = builder.create(); + LockInfo info = new LockInfo(100l, "Agent-1", "Vm-1", 123l, 321l, 432l, 5454l, 578l, 678574l, 21349l, 0l, + 2342342l, 12311l, 13211l, 934l, 8911l, 305934l, 2194l, 892l, 100l, 2321l); + Assert.assertEquals("{\"agentId\":\"Agent-1\",\"vmId\":\"Vm-1\",\"timeStamp\":{\"$numberLong\":\"100\"},\"contendedLockAttempts\":{\"$numberLong\":\"123\"},\"deflations\":{\"$numberLong\":\"321\"},\"emptyNotifications\":{\"$numberLong\":\"432\"},\"failedSpins\":{\"$numberLong\":\"5454\"},\"futileWakeups\":{\"$numberLong\":\"578\"},\"inflations\":{\"$numberLong\":\"678574\"},\"monExtant\":{\"$numberLong\":\"21349\"},\"monInCirculation\":{\"$numberLong\":\"0\"},\"monScavenged\":{\"$numberLong\":\"2342342\"},\"notifications\":{\"$numberLong\":\"12311\"},\"parks\":{\"$numberLong\":\"13211\"},\"privateA\":{\"$numberLong\":\"934\"},\"privateB\":{\"$numberLong\":\"8911\"},\"slowEnter\":{\"$numberLong\":\"305934\"},\"slowExit\":{\"$numberLong\":\"2194\"},\"slowNotify\":{\"$numberLong\":\"892\"},\"slowNotifyAll\":{\"$numberLong\":\"100\"},\"successfulSpins\":{\"$numberLong\":\"2321\"}}", gson.toJson(info)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/internal/ThreadHarvestingStatusTypeAdapterTest.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.redhat.thermostat.thread.model.ThreadHarvestingStatus; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ThreadHarvestingStatusTypeAdapterTest { + + @Test + public void testWrite() { + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(ThreadHarvestingStatus.class, new ThreadHarvestingStatusTypeAdapter()); + Gson gson = builder.create(); + ThreadHarvestingStatus status = new ThreadHarvestingStatus(); + status.setAgentId("Agent-1"); + status.setVmId("Vm-1"); + status.setHarvesting(true); + status.setTimeStamp(100l); + assertEquals("{\"agentId\":\"Agent-1\",\"vmId\":\"Vm-1\",\"timeStamp\":{\"$numberLong\":\"100\"},\"collecting\":true}", gson.toJson(status)); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/internal/ThreadSessionTypeAdapterTest.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.redhat.thermostat.thread.model.ThreadSession; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ThreadSessionTypeAdapterTest { + + @Test + public void testWrite() { + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(ThreadSession.class, new ThreadSessionTypeAdapter()); + Gson gson = builder.create(); + ThreadSession session = new ThreadSession(); + session.setAgentId("Agent-1"); + session.setVmId("Vm-1"); + session.setTimeStamp(100l); + session.setSession("Session"); + assertEquals("{\"agentId\":\"Agent-1\",\"vmId\":\"Vm-1\",\"timeStamp\":{\"$numberLong\":\"100\"},\"session\":\"Session\",\"sessionID\":{\"id\":\"Session\"}}", gson.toJson(session)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/internal/ThreadStateTypeAdapterTest.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,69 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.redhat.thermostat.thread.model.ThreadState; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ThreadStateTypeAdapterTest { + + @Test + public void testWrite() { + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(ThreadState.class, new ThreadStateTypeAdapter()); + Gson gson = builder.create(); + ThreadState state = new ThreadState(); + state.setTimeStamp(10l); + state.setAgentId("Agent-1"); + state.setVmId("Vm-1"); + state.setBlockedCount(100l); + state.setBlockedTime(200l); + state.setId(1l); + state.setInNative(true); + state.setSuspended(true); + state.setSession("Session"); + state.setStackTrace("foo.bar.baz"); + state.setName("Thread-1"); + state.setWaitedCount(30l); + state.setWaitedTime(1003l); + assertEquals("{\"agentId\":\"Agent-1\",\"vmId\":\"Vm-1\",\"name\":\"Thread-1\",\"session\":\"Session\",\"id\":{\"$numberLong\":\"1\"},\"suspended\":true,\"inNative\":true,\"blockedCount\":{\"$numberLong\":\"100\"},\"blockedTime\":{\"$numberLong\":\"200\"},\"waitedCount\":{\"$numberLong\":\"30\"},\"waitedTime\":{\"$numberLong\":\"1003\"},\"stackTrace\":\"foo.bar.baz\"}", gson.toJson(state)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/internal/ThreadSummaryTypeAdapterTest.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.GsonBuilder; +import com.google.gson.Gson; +import com.redhat.thermostat.thread.model.ThreadSummary; +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + +public class ThreadSummaryTypeAdapterTest { + + @Test + public void testWrite() { + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(ThreadSummary.class, new ThreadSummaryTypeAdapter()); + Gson gson = builder.create(); + ThreadSummary summary = new ThreadSummary(); + summary.setTimeStamp(10l); + summary.setAgentId("Agent-1"); + summary.setVmId("VM-1"); + summary.setCurrentDaemonThreads(3232l); + summary.setCurrentLiveThreads(2222l); + assertEquals("{\"agentId\":\"Agent-1\",\"vmId\":\"VM-1\",\"timeStamp\":{\"$numberLong\":\"10\"},\"currentLiveThreads\":{\"$numberLong\":\"2222\"},\"daemonThreads\":{\"$numberLong\":\"3232\"}}", gson.toJson(summary)); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/internal/VmDeadLockDataTypeAdapterTest.java Thu May 25 14:13:38 2017 -0400 @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.thread.dao.internal; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.redhat.thermostat.thread.model.VmDeadLockData; +import org.junit.Assert; +import org.junit.Test; + +public class VmDeadLockDataTypeAdapterTest { + + @Test + public void testWrite() { + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(VmDeadLockData.class, new VmDeadLockDataTypeAdapter()); + Gson gson = builder.create(); + VmDeadLockData data = new VmDeadLockData(); + data.setTimeStamp(100l); + data.setAgentId("Agent-1"); + data.setVmId("Vm-1"); + data.setDeadLockDescription("This is a description"); + Assert.assertEquals("{\"agentId\":\"Agent-1\",\"vmId\":\"Vm-1\",\"timeStamp\":{\"$numberLong\":\"100\"},\"description\":\"This is a description\"}", gson.toJson(data)); + } +}