1 /*
2  * Copyright (C) 2015 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 
17 package com.android.ahat;
18 
19 import com.android.ahat.heapdump.AhatInstance;
20 import com.android.ahat.heapdump.AhatSnapshot;
21 import java.io.IOException;
22 import java.io.OutputStream;
23 import java.io.PrintStream;
24 import org.junit.Test;
25 
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28 
29 public class PerformanceTest {
30   private static class NullOutputStream extends OutputStream {
write(int b)31     public void write(int b) throws IOException {
32     }
33   }
34 
35   @Test
bigArray()36   public void bigArray() throws IOException {
37     // It should not take more than 1 second to load the default object view
38     // for any object, including big arrays.
39     TestDump dump = TestDump.getTestDump();
40 
41     AhatInstance bigArray = dump.getDumpedAhatInstance("bigArray");
42     assertNotNull(bigArray);
43 
44     AhatSnapshot snapshot = dump.getAhatSnapshot();
45     AhatHandler handler = new ObjectHandler(snapshot);
46 
47     PrintStream ps = new PrintStream(new NullOutputStream());
48     HtmlDoc doc = new HtmlDoc(ps, DocString.text("bigArray test"), DocString.uri("style.css"));
49     String uri = "http://localhost:7100/object?id=" + bigArray.getId();
50     Query query = new Query(DocString.uri(uri));
51 
52     long start = System.currentTimeMillis();
53     handler.handle(doc, query);
54     long time = System.currentTimeMillis() - start;
55     assertTrue("bigArray took too long: " + time + "ms", time < 1000);
56   }
57 }
58