private void invokeOnTimer(DoFn<String, String> fn, String timerId) { OnTimerInvokers.forTimer(fn, timerId).invokeOnTimer(mockArgumentProvider); }
/** @return the {@link DoFnInvoker} for the given {@link DoFn}. */ public <InputT, OutputT> DoFnInvoker<InputT, OutputT> newByteBuddyInvoker( DoFnSignature signature, DoFn<InputT, OutputT> fn) { checkArgument( signature.fnClass().equals(fn.getClass()), "Signature is for class %s, but fn is of class %s", signature.fnClass(), fn.getClass()); try { @SuppressWarnings("unchecked") DoFnInvokerBase<InputT, OutputT, DoFn<InputT, OutputT>> invoker = (DoFnInvokerBase<InputT, OutputT, DoFn<InputT, OutputT>>) getByteBuddyInvokerConstructor(signature).newInstance(fn); for (OnTimerMethod onTimerMethod : signature.onTimerMethods().values()) { invoker.addOnTimerInvoker( onTimerMethod.id(), OnTimerInvokers.forTimer(fn, onTimerMethod.id())); } return invoker; } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) { throw new RuntimeException("Unable to bind invoker for " + fn.getClass(), e); } }
/** This is a change-detector test that the generated name is stable across runs. */ @Test public void testStableName() { OnTimerInvoker<Void, Void> invoker = OnTimerInvokers.forTimer(new StableNameTestDoFn(), StableNameTestDoFn.TIMER_ID); assertThat( invoker.getClass().getName(), equalTo( String.format( "%s$%s$%s$%s", StableNameTestDoFn.class.getName(), OnTimerInvoker.class.getSimpleName(), "timeridwithspecialChars" /* alphanum only; human readable but not unique */, "dGltZXItaWQud2l0aCBzcGVjaWFsQ2hhcnN7fQ" /* base64 encoding of UTF-8 timerId */))); } }