@@ -32,9 +32,8 @@ this example. Run:
3232```
3333
3434This will start a local functions service, a local flow completion
35- service, and will set up a ` myapp ` application and three routes: ` /resize128 ` ,
36- ` /resize256 ` and ` /resize512 ` . The routes are implemented as Fn functions
37- which just invoke ` imagemagick ` to convert the images to the specified sizes.
35+ service, and will set up a ` myapp ` application and three functions: ` resize128 ` ,
36+ ` resize256 ` and ` resize512 ` . These functions just invoke ` imagemagick ` to convert the images to the specified sizes.
3837
3938The setup script also starts a docker container with an object storage daemon
4039based on ` minio ` (with access key ` alpha ` and secret key ` betabetabetabeta ` ).
@@ -48,14 +47,9 @@ docker container, so that you can verify when the thumbnails are uploaded.
4847Build the function locally:
4948
5049``` bash
51- $ fn build
50+ $ fn deploy --local --app myapp
5251```
5352
54- Create a route to host the function:
55-
56- ``` bash
57- $ fn create route myapp /async-thumbnails
58- ```
5953
6054Configure the app. In order to do this you must determine the IP address of the
6155storage server docker container:
@@ -68,18 +62,18 @@ $ docker inspect --type container -f '{{range .NetworkSettings.Networks}}{{.IPAd
6862and then use it as the storage host:
6963
7064``` bash
71- $ fn config route myapp /async-thumbnails OBJECT_STORAGE_URL http://172.17.0.4:9000
65+ $ fn config app myapp OBJECT_STORAGE_URL http://172.17.0.4:9000
7266myapp /async-thumbnails updated OBJECT_STORAGE_URL with http://172.17.0.4:9000
73- $ fn config route myapp /async-thumbnails OBJECT_STORAGE_ACCESS alpha
67+ $ fn config app myapp OBJECT_STORAGE_ACCESS alpha
7468myapp /async-thumbnails updated OBJECT_STORAGE_ACCESS with alpha
75- $ fn config route myapp /async-thumbnails OBJECT_STORAGE_SECRET betabetabetabeta
69+ $ fn config app myapp OBJECT_STORAGE_SECRET betabetabetabeta
7670myapp /async-thumbnails updated OBJECT_STORAGE_SECRET with betabetabetabeta
7771```
7872
7973Invoke the function by passing the provided test image:
8074
8175``` bash
82- $ curl -X POST --data-binary @test-image.png -H " Content-type: application/octet-stream" " http://localhost:8080/r /myapp/async-thumbnails"
76+ $ curl -X POST --data-binary @test-image.png -H " Content-type: application/octet-stream" " http://localhost:8080/t /myapp/async-thumbnails"
8377{" imageId" :" bd74fff4-0388-4c6f-82f2-8cde9ba9b6fc" }
8478```
8579
@@ -116,6 +110,13 @@ public class ThumbnailsFunction {
116110 .orElseThrow(() - > new RuntimeException (" Missing configuration: OBJECT_STORAGE_ACCESS" ));
117111 storageSecretKey = ctx. getConfigurationByKey(" OBJECT_STORAGE_SECRET" )
118112 .orElseThrow(() - > new RuntimeException (" Missing configuration: OBJECT_STORAGE_SECRET" ));
113+
114+ resize128ID = ctx. getConfigurationByKey(" RESIZE_128_FN_ID" )
115+ .orElseThrow(() - > new RuntimeException (" Missing configuration: RESIZE_128_FN_ID" ));
116+ resize256ID = ctx. getConfigurationByKey(" RESIZE_256_FN_ID" )
117+ .orElseThrow(() - > new RuntimeException (" Missing configuration: RESIZE_256_FN_ID" ));
118+ resize512ID = ctx. getConfigurationByKey(" RESIZE_512_FN_ID" )
119+ .orElseThrow(() - > new RuntimeException (" Missing configuration: RESIZE_512_FN_ID" ));
119120 }
120121
121122 // ...
@@ -155,11 +156,11 @@ public class ThumbnailsFunction {
155156 Flow runtime = Flows . currentFlow();
156157
157158 runtime. allOf(
158- runtime. invokeFunction(" myapp/resize128 " , HttpMethod . POST , Headers . emptyHeaders(), imageBuffer)
159+ runtime. invokeFunction(resize128ID , HttpMethod . POST , Headers . emptyHeaders(), imageBuffer)
159160 .thenAccept((img) - > objectUpload(img. getBodyAsBytes(), id + " -128.png" )),
160- runtime. invokeFunction(" myapp/resize256 " , HttpMethod . POST , Headers . emptyHeaders(), imageBuffer)
161+ runtime. invokeFunction(resize256ID , HttpMethod . POST , Headers . emptyHeaders(), imageBuffer)
161162 .thenAccept((img) - > objectUpload(img. getBodyAsBytes(), id + " -256.png" )),
162- runtime. invokeFunction(" myapp/resize512 " , HttpMethod . POST , Headers . emptyHeaders(), imageBuffer)
163+ runtime. invokeFunction(resize512ID , HttpMethod . POST , Headers . emptyHeaders(), imageBuffer)
163164 .thenAccept((img) - > objectUpload(img. getBodyAsBytes(), id + " -512.png" )),
164165 runtime. supply(() - > objectUpload(imageBuffer, id + " .png" ))
165166 );
@@ -218,8 +219,9 @@ in [Testing Functions](../../docs/TestingFunctions.md).
218219``` java
219220public class ThumbnailsFunctionTest {
220221
221- @Rule
222- public final FnTestingRule testing = FnTestingRule . createDefault();
222+ @Rule
223+ public final FnTestingRule fn = FnTestingRule . createDefault();
224+ private final FlowTesting flow = FlowTesting . create(fn);
223225
224226 // ...
225227}
@@ -259,20 +261,22 @@ public class ThumbnailsFunctionTest {
259261
260262 @Test
261263 public void testThumbnail () {
262- testing
263264
264- .setConfig(" OBJECT_STORAGE_URL" , " http://localhost:" + mockServer. port())
265- .setConfig(" OBJECT_STORAGE_ACCESS" , " alpha" )
266- .setConfig(" OBJECT_STORAGE_SECRET" , " betabetabetabeta" )
265+ fn. setConfig(" OBJECT_STORAGE_URL" , " http://localhost:" + mockServer. port())
266+ .setConfig(" OBJECT_STORAGE_ACCESS" , " alpha" )
267+ .setConfig(" OBJECT_STORAGE_SECRET" , " betabetabetabeta" )
268+ .setConfig(" RESIZE_128_FN_ID" ," myapp/resize128" )
269+ .setConfig(" RESIZE_256_FN_ID" ," myapp/resize256" )
270+ .setConfig(" RESIZE_512_FN_ID" ," myapp/resize512" );
267271
268- .givenFn(" myapp/resize128" )
272+ flow . givenFn(" myapp/resize128" )
269273 .withAction((data) - > " 128" . getBytes())
270274 .givenFn(" myapp/resize256" )
271275 .withAction((data) - > " 256" . getBytes())
272276 .givenFn(" myapp/resize512" )
273277 .withAction((data) - > " 512" . getBytes())
274278
275- .givenEvent()
279+ fn . givenEvent()
276280 .withBody(" testing" . getBytes())
277281 .enqueue();
278282
@@ -301,21 +305,23 @@ public class ThumbnailsFunctionTest {
301305
302306 @Test
303307 public void anExternalFunctionFailure () {
304- testing
305- .setConfig(" OBJECT_STORAGE_URL" , " http://localhost:" + mockServer. port())
306- .setConfig(" OBJECT_STORAGE_ACCESS" , " alpha" )
307- .setConfig(" OBJECT_STORAGE_SECRET" , " betabetabetabeta" )
308-
309- .givenFn(" myapp/resize128" )
310- .withResult(" 128" . getBytes())
311- .givenFn(" myapp/resize256" )
312- .withResult(" 256" . getBytes())
313- .givenFn(" myapp/resize512" )
314- .withFunctionError()
315-
316- .givenEvent()
317- .withBody(" testing" . getBytes())
318- .enqueue();
308+ fn. setConfig(" OBJECT_STORAGE_URL" , " http://localhost:" + mockServer. port())
309+ .setConfig(" OBJECT_STORAGE_ACCESS" , " alpha" )
310+ .setConfig(" OBJECT_STORAGE_SECRET" , " betabetabetabeta" )
311+ .setConfig(" RESIZE_128_FN_ID" ," myapp/resize128" )
312+ .setConfig(" RESIZE_256_FN_ID" ," myapp/resize256" )
313+ .setConfig(" RESIZE_512_FN_ID" ," myapp/resize512" );
314+
315+ flow. givenFn(" myapp/resize128" )
316+ .withResult(" 128" . getBytes())
317+ .givenFn(" myapp/resize256" )
318+ .withResult(" 256" . getBytes())
319+ .givenFn(" myapp/resize512" )
320+ .withFunctionError();
321+
322+ fn. givenEvent()
323+ .withBody(" testing" . getBytes())
324+ .enqueue();
319325
320326 // Mock the http endpoint
321327 mockMinio();
0 commit comments