From dev-return-16992-archive-asf-public=cust-asf.ponee.io@nifi.apache.org Thu Apr 12 23:41:26 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id F2A31180634 for ; Thu, 12 Apr 2018 23:41:25 +0200 (CEST) Received: (qmail 86436 invoked by uid 500); 12 Apr 2018 21:41:24 -0000 Mailing-List: contact dev-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list dev@nifi.apache.org Received: (qmail 86420 invoked by uid 99); 12 Apr 2018 21:41:24 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Apr 2018 21:41:24 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id B816CC0146 for ; Thu, 12 Apr 2018 21:41:23 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.879 X-Spam-Level: ** X-Spam-Status: No, score=2.879 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id BvYX7iLuGG3p for ; Thu, 12 Apr 2018 21:41:19 +0000 (UTC) Received: from mail-oi0-f45.google.com (mail-oi0-f45.google.com [209.85.218.45]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id D5CFC5F254 for ; Thu, 12 Apr 2018 21:41:18 +0000 (UTC) Received: by mail-oi0-f45.google.com with SMTP id q71-v6so6596932oic.6 for ; Thu, 12 Apr 2018 14:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=0B3XUflJ5TptiYhKGni4qIHXeLZIJ7tTo1QdYtZMcMk=; b=TDIYAT3e2ZQYY/VFShpIrt2jq+SL5wXJlYubnLuIDyKrjo3Tq4gYAlw2i204aatuYb PEDLzSKesig4MZoxIrgWLDESQ40B04Qg3G4mlKuzLAPxzkqi5sfgiCCrflXOTEGgQZJK 91/AuStlomJree1RD/D1IC7RquPPR15sH2A8emN2dy0pdL8u/KnABuwqftH2EbLbBPtr t9vLN6Jc7pwMrt3Sw9aMeRDlxbS+OoNQrfxnXrwHxZCBukqIdbFiZwc73yF/AsmSdRZ7 Waktd/lPhBwo59oGGwlFWSxZz0F2j7SpmqSWhl617g2ibm4oG/DK5jq2W79TIactyBHT wbfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=0B3XUflJ5TptiYhKGni4qIHXeLZIJ7tTo1QdYtZMcMk=; b=nF7yxqj0fLTX7smzK/pjFXvQj5bay5jynl0EvbKTL8vJn5YZjNFAiR25VswNFmc5gL fmlzutlO/UJG8j3VomawERFbP4g00B8NDWz6W8IoQtOcXukyUR43pKbD3rtts8p2e6eZ 8YPvAO20cBGFLxflZTSkoE6f50wt855y49KhGDl5/wxVrbsDRuaeyEI7WvtUOyaMuio3 TiN2y/P6CoDj/eda7+IbQ+Ju6v2TW90v6UHoZ/T8HrMRCJfHu5BirXh8c1FF7vxKPw71 3OF8t90teNMqT1EWv1XzLvD/D4scNKq0SD+Grep7VNYau9DXd69KMz+TzVVxBRxv5b/K Qrrg== X-Gm-Message-State: ALQs6tAZfULMRIW5C7OdqXHJf9LmfEfHM3D4PfyjYWJezmUrpb8Qva0h RLMxZLWXHDgo7skDpRwee4omzhQQrW0EgGpyjvQgTg== X-Google-Smtp-Source: AIpwx49j2C4hVlZwHlpYpxidkoxOL3T8pXbBidftahbLPw7yYCbBY/IzI0plIbCZI4ljXixEOAaQSv+l03IsARt95z8= X-Received: by 2002:aca:4085:: with SMTP id n127-v6mr6491706oia.205.1523569271627; Thu, 12 Apr 2018 14:41:11 -0700 (PDT) MIME-Version: 1.0 References: <933c8bbd-ace0-1b3c-8f5f-ad0d42548ff2@windofkeltia.com> <8d1eb581-1a19-fc4c-1e8d-4382b1a0603e@windofkeltia.com> In-Reply-To: <8d1eb581-1a19-fc4c-1e8d-4382b1a0603e@windofkeltia.com> From: Bryan Bende Date: Thu, 12 Apr 2018 21:41:01 +0000 Message-ID: Subject: Re: Calling getLogger() from @OnScheduled, @OnStopped, etc. To: dev@nifi.apache.org Content-Type: multipart/alternative; boundary="00000000000039e4a30569ad9d81" --00000000000039e4a30569ad9d81 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable The example processor you showed won=E2=80=99t work because you are calling getLogger() inline as part of the variable declaration. The logger is given to the processor in an init method which hasn=E2=80=99t= been called yet at that point, so that is assigning null to the variable. Generally you should just call getLogger() whenever it is needed, or you could assign it to a variable from inside OnScheduled. On Thu, Apr 12, 2018 at 5:28 PM Russell Bateman wrote: > Thanks for responding, Andy. > > I am able to use it, like you, in onTrigger(). Where I haven't been able > to use it is from annotated methods (in the sense that onTrigger()isn't > annotated except by @Overridewhich is not relevant in this question). > Imagine: > > public class Fun extends AbstractProcessor > { > private ComponentLog logger =3D getLogger(); > > @Override > public void onTrigger( final ProcessContext context, final > ProcessSession session ) throws ProcessException > { > logger.trace( "[PROFILE] onTrigger()" );*/* A */* > ... > } > > *@OnScheduled* > public void processProperties( final ProcessContext context ) > { > logger.trace( "[PROFILE] processProperties()" );*/* B */* > ... > } > > *@OnStopped* > public void dropEverything() > { > logger.trace( "[PROFILE] dropEverything()" );*/* C */* > ... > } > ... > } > > > Now, imaging suitable test code, FunTest.test() which sets up > > runner =3D TestRunners.newTestRunner( processor =3D new Fun() ); > > etc., then > > runner.run( 1 ); > > Above, instance A works fine (it's the one you illustrated in footnote > [1]). Instances B and C cause the error: > > java.lang.AssertionError: Could not invoke methods annotated with > @OnScheduled (or @OnStopped) annotation due to: > java.lang.reflect.InvocationTargetException > > Russ > > On 04/12/2018 02:52 PM, Andy LoPresto wrote: > > Hi Russ, > > > > Are you saying the code that breaks is having =E2=80=9CgetLogger()=E2= =80=9D executed > > inside one of the processor lifecycle methods (i.e. > > GetFile#onTrigger()) or in your test code (i.e. > > GetFileTest#testOnTriggerShouldReadFile())? > > > > I=E2=80=99m not aware of anything with the JUnit runner that would caus= e > > issues here. I use the loggers extensively in both my application code > > [1] and the tests [2]. Obviously in the tests, I instantiate a new > > Logger instance for the test class. > > > > Can you share an example of the code that breaks this for you? > > > > [1] > > > https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard= -bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/s= tandard/EncryptContent.java#L511 > > [2] > > > https://github.com/apache/nifi/pull/2628/files#diff-e9cfa232683ae75b1fc50= 5d6c9bd3b24R447 > > > > Andy LoPresto > > alopresto@apache.org > > /alopresto.apache@gmail.com / > > PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4 BACE 3C6E F65B 2F7D EF69 > > > >> On Apr 12, 2018, at 3:46 PM, Russell Bateman >> > wrote: > >> > >> I seem to crash NiFi JUnit test runner when I have code that calls > >> getLogger()or attempts to make use of the product of calling > >> getLogger()in situations where some context (probably) is missing > >> like methods annotated for call at "special" times. This makes sense, > >> but is there a technique I can use to profile my custom processor in > >> order to observe (easily, such as using the logger) the behavior of > >> (i.e.: log-TRACE through) my processor in respect to @OnScheduled, > >> @OnUnscheduled, @OnStopped, etc. moments? > >> > >> Many thanks, > >> Russ > > > > -- Sent from Gmail Mobile --00000000000039e4a30569ad9d81--