Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: components/cronet/android/test/javatests/src/org/chromium/net/MetricsTestUtil.java

Issue 2360813003: [Cronet] Pass metrics information from C++ BidirectionalStream to Java (Closed)
Patch Set: self review Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/cronet/android/test/javatests/src/org/chromium/net/BidirectionalStreamTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import static junit.framework.Assert.assertNotNull; 7 import static junit.framework.Assert.assertNotNull;
8 import static junit.framework.Assert.assertNull; 8 import static junit.framework.Assert.assertNull;
9 import static junit.framework.Assert.assertTrue; 9 import static junit.framework.Assert.assertTrue;
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 } 43 }
44 } 44 }
45 45
46 /** 46 /**
47 * RequestFinishedInfo.Listener for testing, which saves the RequestFinished Info 47 * RequestFinishedInfo.Listener for testing, which saves the RequestFinished Info
48 */ 48 */
49 public static class TestRequestFinishedListener extends RequestFinishedInfo. Listener { 49 public static class TestRequestFinishedListener extends RequestFinishedInfo. Listener {
50 private RequestFinishedInfo mRequestInfo; 50 private RequestFinishedInfo mRequestInfo;
51 private ConditionVariable mBlock; 51 private ConditionVariable mBlock;
52 private int mNumExpectedRequests = -1;
53 52
54 // TODO(mgersh): it's weird that you can use either this constructor or blockUntilDone() but 53 // TODO(mgersh): it's weird that you can use either this constructor or blockUntilDone() but
55 // not both. Either clean it up or document why it has to work this way. 54 // not both. Either clean it up or document why it has to work this way.
56 public TestRequestFinishedListener(Executor executor) { 55 public TestRequestFinishedListener(Executor executor) {
57 super(executor); 56 super(executor);
58 } 57 }
59 58
60 public TestRequestFinishedListener(int numExpectedRequests) {
61 super(Executors.newSingleThreadExecutor());
62 mNumExpectedRequests = numExpectedRequests;
63 mBlock = new ConditionVariable();
64 }
65
66 public TestRequestFinishedListener() { 59 public TestRequestFinishedListener() {
67 super(Executors.newSingleThreadExecutor()); 60 super(Executors.newSingleThreadExecutor());
68 mNumExpectedRequests = 1;
69 mBlock = new ConditionVariable(); 61 mBlock = new ConditionVariable();
70 } 62 }
71 63
72 public RequestFinishedInfo getRequestInfo() { 64 public RequestFinishedInfo getRequestInfo() {
73 return mRequestInfo; 65 return mRequestInfo;
74 } 66 }
75 67
76 @Override 68 @Override
77 public void onRequestFinished(RequestFinishedInfo requestInfo) { 69 public void onRequestFinished(RequestFinishedInfo requestInfo) {
78 assertNull("onRequestFinished called repeatedly", mRequestInfo); 70 assertNull("onRequestFinished called repeatedly", mRequestInfo);
79 assertNotNull(requestInfo); 71 assertNotNull(requestInfo);
80 mRequestInfo = requestInfo; 72 mRequestInfo = requestInfo;
81 mNumExpectedRequests--; 73 mBlock.open();
82 if (mNumExpectedRequests == 0) {
83 mBlock.open();
84 }
85 } 74 }
86 75
87 public void blockUntilDone() { 76 public void blockUntilDone() {
88 mBlock.block(); 77 mBlock.block();
89 } 78 }
90 79
91 public void reset() { 80 public void reset() {
92 mBlock.close(); 81 mBlock.close();
93 mNumExpectedRequests = 1;
94 mRequestInfo = null; 82 mRequestInfo = null;
95 } 83 }
96 } 84 }
97 85
86 // Helper method to assert date2 is equals to or after date1.
87 // Some implementation of java.util.Date broke asymmetric property, so
mgersh 2016/10/06 14:44:09 Huh, weird. I'm curious where? nit: "asymmetric p
xunjieli 2016/10/06 16:14:21 Done. ah, you are right! http://stackoverflow.com
xunjieli 2016/10/06 16:16:17 s/paranoia/paranoid
88 // check both directions.
89 public static void assertAfter(Date date1, Date date2) {
mgersh 2016/10/06 14:44:09 Thanks for adding this. There are a few places in
xunjieli 2016/10/06 16:14:21 Acknowledged. I will leave it to you then. My brai
90 assertTrue("date1: " + date1.getTime() + ", date2: " + date2.getTime(),
91 date1.after(date2) || date1.equals(date2) || date2.equals(date1) );
92 }
93
98 /** 94 /**
99 * Check existence of all the timing metrics that apply to most test request s, 95 * Check existence of all the timing metrics that apply to most test request s,
100 * except those that come from net::LoadTimingInfo::ConnectTiming. 96 * except those that come from net::LoadTimingInfo::ConnectTiming.
101 * Also check some timing differences, focusing on things we can't check wit h asserts in the 97 * Also check some timing differences, focusing on things we can't check wit h asserts in the
102 * CronetMetrics constructor. 98 * CronetMetrics constructor.
103 * Don't check push times here. 99 * Don't check push times here.
104 */ 100 */
105 public static void checkTimingMetrics( 101 public static void checkTimingMetrics(
106 RequestFinishedInfo.Metrics metrics, Date startTime, Date endTime) { 102 RequestFinishedInfo.Metrics metrics, Date startTime, Date endTime) {
107 assertNotNull(metrics.getRequestStart()); 103 assertNotNull(metrics.getRequestStart());
108 assertTrue(metrics.getRequestStart().after(startTime) 104 assertAfter(metrics.getRequestStart(), startTime);
109 || metrics.getRequestStart().equals(startTime));
110 assertNotNull(metrics.getSendingStart()); 105 assertNotNull(metrics.getSendingStart());
111 assertTrue(metrics.getSendingStart().after(startTime) 106 assertAfter(metrics.getSendingStart(), startTime);
112 || metrics.getSendingStart().equals(startTime));
113 assertNotNull(metrics.getSendingEnd()); 107 assertNotNull(metrics.getSendingEnd());
114 assertTrue(metrics.getSendingEnd().before(endTime)); 108 assertTrue(metrics.getSendingEnd().before(endTime));
115 assertNotNull(metrics.getResponseStart()); 109 assertNotNull(metrics.getResponseStart());
116 assertTrue(metrics.getResponseStart().after(startTime)); 110 assertTrue(metrics.getResponseStart().after(startTime));
117 assertNotNull(metrics.getResponseEnd()); 111 assertNotNull(metrics.getResponseEnd());
118 assertTrue(metrics.getResponseEnd().before(endTime) 112 assertAfter(endTime, metrics.getResponseEnd());
119 || metrics.getResponseEnd().equals(endTime));
120 // Entire request should take more than 0 ms 113 // Entire request should take more than 0 ms
121 assertTrue(metrics.getResponseEnd().getTime() - metrics.getRequestStart( ).getTime() > 0); 114 assertTrue(metrics.getResponseEnd().getTime() - metrics.getRequestStart( ).getTime() > 0);
122 } 115 }
123 116
124 /** 117 /**
125 * Check that the timing metrics which come from net::LoadTimingInfo::Connec tTiming exist, 118 * Check that the timing metrics which come from net::LoadTimingInfo::Connec tTiming exist,
126 * except SSL times in the case of non-https requests. 119 * except SSL times in the case of non-https requests.
127 */ 120 */
128 public static void checkHasConnectTiming( 121 public static void checkHasConnectTiming(
129 RequestFinishedInfo.Metrics metrics, Date startTime, Date endTime, b oolean isSsl) { 122 RequestFinishedInfo.Metrics metrics, Date startTime, Date endTime, b oolean isSsl) {
130 assertNotNull(metrics.getDnsStart()); 123 assertNotNull(metrics.getDnsStart());
131 assertTrue( 124 assertAfter(metrics.getDnsStart(), startTime);
132 metrics.getDnsStart().after(startTime) || metrics.getDnsStart(). equals(startTime));
133 assertNotNull(metrics.getDnsEnd()); 125 assertNotNull(metrics.getDnsEnd());
134 assertTrue(metrics.getDnsEnd().before(endTime)); 126 assertTrue(metrics.getDnsEnd().before(endTime));
135 assertNotNull(metrics.getConnectStart()); 127 assertNotNull(metrics.getConnectStart());
136 assertTrue(metrics.getConnectStart().after(startTime) 128 assertAfter(metrics.getConnectStart(), startTime);
137 || metrics.getConnectStart().equals(startTime));
138 assertNotNull(metrics.getConnectEnd()); 129 assertNotNull(metrics.getConnectEnd());
139 assertTrue(metrics.getConnectEnd().before(endTime)); 130 assertTrue(metrics.getConnectEnd().before(endTime));
140 if (isSsl) { 131 if (isSsl) {
141 assertNotNull(metrics.getSslStart()); 132 assertNotNull(metrics.getSslStart());
142 assertTrue(metrics.getSslStart().after(startTime) 133 assertAfter(metrics.getSslStart(), startTime);
143 || metrics.getSslStart().equals(startTime));
144 assertNotNull(metrics.getSslEnd()); 134 assertNotNull(metrics.getSslEnd());
145 assertTrue(metrics.getSslEnd().before(endTime)); 135 assertTrue(metrics.getSslEnd().before(endTime));
146 } else { 136 } else {
147 assertNull(metrics.getSslStart()); 137 assertNull(metrics.getSslStart());
148 assertNull(metrics.getSslEnd()); 138 assertNull(metrics.getSslEnd());
149 } 139 }
150 } 140 }
151 141
152 /** 142 /**
153 * Check that the timing metrics from net::LoadTimingInfo::ConnectTiming don 't exist. 143 * Check that the timing metrics from net::LoadTimingInfo::ConnectTiming don 't exist.
154 */ 144 */
155 public static void checkNoConnectTiming(RequestFinishedInfo.Metrics metrics) { 145 public static void checkNoConnectTiming(RequestFinishedInfo.Metrics metrics) {
156 assertNull(metrics.getDnsStart()); 146 assertNull(metrics.getDnsStart());
157 assertNull(metrics.getDnsEnd()); 147 assertNull(metrics.getDnsEnd());
158 assertNull(metrics.getSslStart()); 148 assertNull(metrics.getSslStart());
159 assertNull(metrics.getSslEnd()); 149 assertNull(metrics.getSslEnd());
160 assertNull(metrics.getConnectStart()); 150 assertNull(metrics.getConnectStart());
161 assertNull(metrics.getConnectEnd()); 151 assertNull(metrics.getConnectEnd());
162 } 152 }
163 } 153 }
OLDNEW
« no previous file with comments | « components/cronet/android/test/javatests/src/org/chromium/net/BidirectionalStreamTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698