Skip to content

Commit adbd845

Browse files
Copilotlarohra
andauthored
Deduplicate test host message response handling
Agent-Logs-Url: https://github.com/larohra/azure-functions-java-worker/sessions/db76de91-28a8-4391-b3a2-d8796d6725e4 Co-authored-by: larohra <41490930+larohra@users.noreply.github.com>
1 parent 5a9ed39 commit adbd845

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

src/test/java/com/microsoft/azure/functions/worker/test/utilities/FunctionsTestHost.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,7 @@ void handleMessage(String requestId, Function<StreamingMessage, StreamingMessage
203203
this.getResponseCondition(requestId).await(RESPONSE_POLL_MILLIS, TimeUnit.MILLISECONDS);
204204
FunctionsTestHost.this.throwIfListeningFailed();
205205
}
206-
StreamingMessage message = this.respValue.get(requestId);
207-
StreamingMessage response = null;
208-
if (handler != null) {
209-
response = handler.apply(message);
210-
}
211-
if (response != null) {
212-
this.responder.get(requestId).onNext(response);
213-
}
206+
this.respondToMessage(requestId, handler);
214207
} finally {
215208
this.lock.unlock();
216209
}
@@ -230,19 +223,23 @@ void handleMessageWithTimeout(String requestId, Function<StreamingMessage, Strea
230223
long waitMillis = Math.max(1L, Math.min(TimeUnit.NANOSECONDS.toMillis(remainingNanos), RESPONSE_POLL_MILLIS));
231224
this.getResponseCondition(requestId).await(waitMillis, TimeUnit.MILLISECONDS);
232225
}
233-
StreamingMessage message = this.respValue.get(requestId);
234-
StreamingMessage response = null;
235-
if (handler != null) {
236-
response = handler.apply(message);
237-
}
238-
if (response != null) {
239-
this.responder.get(requestId).onNext(response);
240-
}
226+
this.respondToMessage(requestId, handler);
241227
} finally {
242228
this.lock.unlock();
243229
}
244230
}
245231

232+
private void respondToMessage(String requestId, Function<StreamingMessage, StreamingMessage> handler) {
233+
StreamingMessage message = this.respValue.get(requestId);
234+
StreamingMessage response = null;
235+
if (handler != null) {
236+
response = handler.apply(message);
237+
}
238+
if (response != null) {
239+
this.responder.get(requestId).onNext(response);
240+
}
241+
}
242+
246243
private StreamingMessage initWorker() {
247244
WorkerInitRequest.Builder request = WorkerInitRequest.newBuilder().setHostVersion("2.0.0");
248245
return StreamingMessage.newBuilder().setRequestId(INITWORKER_REQID).setWorkerInitRequest(request).build();

0 commit comments

Comments
 (0)