• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tradefed.util.hostmetric;
17 
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertNull;
20 import static org.junit.Assert.assertTrue;
21 
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.JUnit4;
26 
27 import java.util.Map;
28 
29 /** Unit tests for {@link HeapHostMonitor}. */
30 @RunWith(JUnit4.class)
31 public class HeapHostMonitorTest {
32 
33     private HeapHostMonitor mMonitor;
34     private Map<String, String> mArgsLogged = null;
35 
36     @Before
setUp()37     public void setUp() {
38         mArgsLogged = null;
39         mMonitor =
40                 new HeapHostMonitor() {
41                     @Override
42                     void logEvent(Map<String, String> args) {
43                         mArgsLogged = args;
44                     }
45                 };
46     }
47 
48     /** Test that an event is logged with the memory key in it. */
49     @Test
testDispatchOfHeap()50     public void testDispatchOfHeap() {
51         assertNull(mArgsLogged);
52         mMonitor.dispatch();
53         assertNotNull(mArgsLogged);
54         assertNotNull(mArgsLogged.get(HeapHostMonitor.HEAP_KEY));
55         // make sure it's a positive number
56         long mem = Long.parseLong(mArgsLogged.get(HeapHostMonitor.HEAP_KEY));
57         assertTrue(mem > 0L);
58     }
59 }
60