11/*
2- * Copyright 2002-2017 the original author or authors.
2+ * Copyright 2002-2018 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .http .server .reactive ;
1818
19+ import java .time .Duration ;
1920import java .util .Arrays ;
2021import java .util .Collections ;
2122import java .util .HashMap ;
2223import java .util .Map ;
24+ import java .util .concurrent .atomic .AtomicBoolean ;
2325
2426import org .junit .Test ;
2527import reactor .core .publisher .Mono ;
@@ -109,7 +111,7 @@ public void matchWithNativeContextPath() {
109111 }
110112
111113 @ Test
112- public void notFound () throws Exception {
114+ public void notFound () {
113115 TestHttpHandler handler1 = new TestHttpHandler ();
114116 TestHttpHandler handler2 = new TestHttpHandler ();
115117
@@ -123,11 +125,33 @@ public void notFound() throws Exception {
123125 assertEquals (HttpStatus .NOT_FOUND , response .getStatusCode ());
124126 }
125127
128+ @ Test // SPR-17144
129+ public void notFoundWithCommitAction () {
130+
131+ AtomicBoolean commitInvoked = new AtomicBoolean (false );
132+
133+ ServerHttpRequest request = MockServerHttpRequest .get ("/unknown/path" ).build ();
134+ ServerHttpResponse response = new MockServerHttpResponse ();
135+ response .beforeCommit (() -> {
136+ commitInvoked .set (true );
137+ return Mono .empty ();
138+ });
139+
140+ Map <String , HttpHandler > map = new HashMap <>();
141+ TestHttpHandler handler = new TestHttpHandler ();
142+ map .put ("/path" , handler );
143+ new ContextPathCompositeHandler (map ).handle (request , response ).block (Duration .ofSeconds (5 ));
144+
145+ assertNotInvoked (handler );
146+ assertEquals (HttpStatus .NOT_FOUND , response .getStatusCode ());
147+ assertTrue (commitInvoked .get ());
148+ }
149+
126150
127151 private ServerHttpResponse testHandle (String pathToHandle , Map <String , HttpHandler > handlerMap ) {
128152 ServerHttpRequest request = MockServerHttpRequest .get (pathToHandle ).build ();
129153 ServerHttpResponse response = new MockServerHttpResponse ();
130- new ContextPathCompositeHandler (handlerMap ).handle (request , response );
154+ new ContextPathCompositeHandler (handlerMap ).handle (request , response ). block ( Duration . ofSeconds ( 5 )) ;
131155 return response ;
132156 }
133157
0 commit comments