[ 
https://issues.apache.org/jira/browse/BEAM-6872?focusedWorklogId=228562&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-228562
 ]

ASF GitHub Bot logged work on BEAM-6872:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 16/Apr/19 17:00
            Start Date: 16/Apr/19 17:00
    Worklog Time Spent: 10m 
      Work Description: TheNeuralBit commented on pull request #8104: 
[BEAM-6872] Add hook for user-defined JVM initialization in workers
URL: https://github.com/apache/beam/pull/8104#discussion_r275899738
 
 

 ##########
 File path: 
sdks/java/harness/src/test/java/org/apache/beam/fn/harness/FnHarnessTest.java
 ##########
 @@ -56,13 +67,39 @@
           .setRegister(BeamFnApi.RegisterResponse.getDefaultInstance())
           .build();
 
+  private static @Mock Runnable onStartupMock = mock(Runnable.class);
+  private static @Mock Consumer<PipelineOptions> beforeProcessingMock = 
mock(Consumer.class);
+
+  /**
+   * Fake BeamWorkerInitializer that simply forwards calls to mocked functions 
so that they can be
+   * observed in tests.
+   */
+  @AutoService(BeamWorkerInitializer.class)
+  public static class FnHarnessTestInitializer extends BeamWorkerInitializer {
+    @Override
+    public void onStartup() {
+      onStartupMock.run();
+    }
+
+    @Override
+    public void beforeProcessing(PipelineOptions options) {
+      beforeProcessingMock.accept(options);
+    }
+  }
+
   @Test(timeout = 10 * 1000)
   @SuppressWarnings("FutureReturnValueIgnored") // failure will cause test to 
timeout.
   public void testLaunchFnHarnessAndTeardownCleanly() throws Exception {
+    Function<String, String> environmentVariableMock = mock(Function.class);
+
     PipelineOptions options = PipelineOptionsFactory.create();
 
+    when(environmentVariableMock.apply("HARNESS_ID")).thenReturn("id");
 
 Review comment:
   Mockito just gives me an easy way to verify the order in which things 
occurred. I decided to use a mock for the environment variable accessor so I 
could use reading it as a proxy for "starting to do anything other than running 
BeamWorkerInitialzier.onStartup implementations."  That way I can assert the 
proper ordering occured: `onStartup` called, worker initialization (signaled by 
accessing environment), `beforeProcessing` called, start processing data.
   
   I'm definitely fooling myself a bit here, this doesn't really assert that 
`onStartup` is _the first_ thing that happened, just that it happened before 
any initialization based on environment variables. Do you think it would be 
better to just use a lambda for the environment variable accessor, and just 
assert the order `onStartup` -> `beforeProcessing` -> process data?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 228562)
    Time Spent: 5h 10m  (was: 5h)

> Add hook for user-defined JVM initialization in workers
> -------------------------------------------------------
>
>                 Key: BEAM-6872
>                 URL: https://issues.apache.org/jira/browse/BEAM-6872
>             Project: Beam
>          Issue Type: New Feature
>          Components: runner-dataflow
>            Reporter: Brian Hulette
>            Assignee: Brian Hulette
>            Priority: Minor
>          Time Spent: 5h 10m
>  Remaining Estimate: 0h
>
> Expose an interface for users to run some one-time initialization code when a 
> worker starts up.
> This can be useful for things like overriding the Default ZoneRulesProvider, 
> or setting up custom SSL providers.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to