From users-return-3120-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Mon Jan 8 09:12:49 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id F3009180607 for ; Mon, 8 Jan 2018 09:12:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E32E7160C2C; Mon, 8 Jan 2018 08:12:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6B108160C1E for ; Mon, 8 Jan 2018 09:12:47 +0100 (CET) Received: (qmail 30732 invoked by uid 500); 8 Jan 2018 08:12:46 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 30722 invoked by uid 99); 8 Jan 2018 08:12:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jan 2018 08:12:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 993BE180643 for ; Mon, 8 Jan 2018 08:12:45 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-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, HTML_MESSAGE=2, MANY_SPAN_IN_TEXT=1, 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: spamd3-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 (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id gkPybbmKN1YK for ; Mon, 8 Jan 2018 08:12:41 +0000 (UTC) Received: from mail-it0-f43.google.com (mail-it0-f43.google.com [209.85.214.43]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id B97455FB97 for ; Mon, 8 Jan 2018 08:12:40 +0000 (UTC) Received: by mail-it0-f43.google.com with SMTP id 68so8385215ite.4 for ; Mon, 08 Jan 2018 00:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=siI/Rmqnhm3OVvROsD8YzyJTpu3+fnyW/EO7C0FUjgg=; b=eDOHw1R5hHWybAcvr3eacTEnDrg46kwXLHnqeGMdu+yuLKUEL4QFtqvDmc+wKOlBD7 QEnZRWhBpgOAM6rsz/WT/uXIET1n9tZ88gh7pO02aoM4kOb05nDc8yJDMxN9+MRS30Rc TFhZHLMEg5RCHbqlBEfBMZiSX+A7kFTQSkMG7JRZSEzRd/b3C5Dz7Cl4mu0Ai11p8doa PThIk6ic1wm06vqPrfm+9zVfvQYqTxFHNPBKoo4TJB3qN/L0uWTj979xS4fNgPY2ZncG pcW4M3+a+2zIMaVpj4rEDlO3qPc3vMtF2g1HTwXiZXdpWZPkpJhnGR43fdvVPm054ouk aAnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=siI/Rmqnhm3OVvROsD8YzyJTpu3+fnyW/EO7C0FUjgg=; b=OQkCFTEYlBvPauveGkECKYsayZEl6slfoG3Xda2FLbrXKUg41DBK7mxEqXj+9PzhZk f5Q9l6k4PVOffbtgdb/Mb5FP5E3aWKoEELU9GZczbw4EygbIKnQOrqLP4BB2Dg6Ba9iB e2f38fwMI2saUZ7b2lbf5jqz3J6rlM8ZR+DAPSnlwyxmfp5gvZoGCxi5JUf+8nEPy7fG mQ2BeybDUvC+UFOY0F2atvo42XyjvK+BX7Mez30bJ2IFo9MKyh3uES2n1c53/grwH4rW oF1DubLriPUYOnMtcCKCp/DX4k0FDEPva6eb8Z8lBsU+ZKiXBZiuJttramA4nWhdigF0 uB9w== X-Gm-Message-State: AKGB3mLv7Wa1hMNDf/EtdFGSvMrJLqMd6CL8SzGXOZVzc5jOgTVBHIqq X0JAmaE849KLosKj7oqWW868Rj2O5NKhsKRFTD5BGQ== X-Google-Smtp-Source: ACJfBov+aNuv7oU8jWZS9TQ8MicMO11ywAFnykYpbEmGUuc2+iby7RZUMuc+j5NazbFC1fLrmmuGKoa/DrokYW+ilbY= X-Received: by 10.36.50.73 with SMTP id j70mr10337145ita.149.1515399159148; Mon, 08 Jan 2018 00:12:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.155.6 with HTTP; Mon, 8 Jan 2018 00:12:38 -0800 (PST) In-Reply-To: References: <2445A443-73B3-4772-9078-D543E4D965F3@anc.org> From: Mohan Radhakrishnan Date: Mon, 8 Jan 2018 13:42:38 +0530 Message-ID: Subject: Re: Unknown type: METHOD_DEF To: users@groovy.apache.org Content-Type: multipart/alternative; boundary="94eb2c08879292f43305623f5cd7" --94eb2c08879292f43305623f5cd7 Content-Type: text/plain; charset="UTF-8" I couldn't understand the reason as I my Groovy exp. is less. But this Maven configuration fixed it. org.codehaus.gmavenplus gmavenplus-plugin 1.6 addSources addTestSources compile compileTests Thanks, Mohan On 8 January 2018 at 09:14, Mohan Radhakrishnan < radhakrishnan.mohan@gmail.com> wrote: > Hi Keith, > > The error when I run Maven test is this. > > [ERROR] Failed to execute goal org.codehaus.gmaven:gmaven- > plugin:1.2:generateStu > bs (default) on project Automation: startup failed: > [ERROR] /D:/Development_Avecto/Automation/src/main/groovy/ > com/automation/pages/t > ime/ThreadSleeper.groovy: 11: Unknown type: METHOD_DEF at line: 11 column: > 5. Fi > le: /D:/Development_Avecto/Automation/src/main/groovy/ > com/automation/pages/time/ > ThreadSleeper.groovy @ line 11, column 5. > [ERROR] def sleeperWithAction() { > [ERROR] ^ > [ERROR] > [ERROR] 1 error > > But when I execute a test like this from Intellij it passes. > > @Test( expected = SleepInterruptedException.class ) > def void interruptedTest() { > > Thread.currentThread().interrupt() > def sleeper = new AutomationSleeper( ms : 10) > sleeper.sleeper() > } > > I am handling InterruptedException because some Selenium code calls sleep everywhere. > > And the calling code isn't prepared to be interrupted. Moreover there is no descriptive > > message about what the thread is sleeping on. I plan to add some messages so that code that > > calls my 'sleeper' will atleast have messages. The closure could help too. > > Even selenium source code has this section probably because that framework isn't required to deal with > > 'InterruptedException'. It is a web scraping tool. > > > try { > Thread.sleep(50); > } catch (InterruptedException e) { > throw new RuntimeException( e); > } > > > > Thanks, > Mohan > > On 6 January 2018 at 03:47, Keith Suderman wrote: > >> What error are you seeing? Do you see the error at runtime or in your >> IDE? Your code works for me (Groovy 2.4.9) so maybe check for unbalanced >> braces elsewhere in your code. >> >> However, you shouldn't catch/rethrow the InterruptedException as you do. >> The InterruptedException is not thrown for "some reason", it is thrown when >> another thread calls Thread.interrupt() on your thread (e.g. to wake your >> thread up so it can check its state). For example: >> >> Thread t = Thread.start { >> boolean running = true >> while (running) { >> doSomeWork() >> try { >> Thread.sleep(1000) >> } >> catch (InterruptedException e) { >> running = shouldIKeepRunning() >> return true >> } >> } >> } >> // At program shutdown/cleanup >> t.interrupt() >> t.join() >> println "Our thread has termintated." >> >> >> The Closure passed to the Thread.sleep method can be used in place of the >> try/catch block. That is the closure will be called when >> Thread.interrupt() is called on your thread i.e.: >> >> Thread t = Thread.start { >> boolean running = false >> while(running) { >> doSomeWork() >> Thread.sleep(1000) { >> // Called then Thread.sleep() is interrupted. >> running = false >> return true >> } >> } >> } >> // ... >> t.interrupt() >> t.join() >> >> >> Finally, if you are doing complicated threading work you should really be >> using GPars or Java's Executors, ThreadPools, et al. >> >> Cheers, >> Keith >> >> On Jan 5, 2018, at 11:01 AM, Mohan Radhakrishnan < >> radhakrishnan.mohan@gmail.com> wrote: >> >> >> >> >> Hi, >> >> I am new to groovy. Here I tried to create >> >> a simple wrapper around 'sleep'. >> >> I see the error in the subject at 'def'. What's wrong ? >> >> Thanks, >> >> Mohan >> >> /** >> * Our custom sleep logic. >> */ >> trait ThreadSleeper { >> long ms >> Closure cl = {} >> >> /*Sleep with an action taken*/ >> def sleeperWithAction() { >> try{ >> >> Thread.sleep ms, cl >> >> }catch( InterruptedException ie ){ >> throw new SleepInterruptedException( ie, "Thread.sleep is interrupted for "+ >> "some reason [" + ie.getMessage() +"]"); >> } >> } >> >> >> /*If there is no action to be taken then we call this*/ >> def sleeper() { >> try{ >> >> Thread.sleep ms >> >> }catch( InterruptedException ie ){ >> throw new SleepInterruptedException( ie, "Thread.sleep is interrupted for "+ >> "some reason [" + ie.getMessage() +"]"); >> } >> } >> } >> >> >> ---------------------- >> Keith Suderman >> Research Associate >> Department of Computer Science >> Vassar College, Poughkeepsie NY >> suderman@cs.vassar.edu >> >> >> >> >> > --94eb2c08879292f43305623f5cd7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I couldn't understand the reason as I my Groovy exp. i= s less.

But this Maven configuration fixed it.

&=
lt;plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifa= ctId> <version>1.6</version>
<executions
= >
&l= t;execution>
<goals>
<goal>addSources</goal>
<goal>addTestSo= urces</goal>=
<<= /span>goal>compile<= /goal>
<goal>compileTests</goal>
</goals>
</execution
>
</execu= tions></= plugin><= br>

Thanks,<=
/span>
Mohan=

On 8 January 2018 at 09:14, Mohan Radhakrishnan &= lt;radha= krishnan.mohan@gmail.com> wrote:
Hi Keith,

The error when I run Ma= ven test is this.

[ERROR] Failed to execute g= oal org.codehaus.gmaven:gmaven-plugin:1.2:generateStu
bs (de= fault) on project Automation: startup failed:
[ERROR] /D:/Develop= ment_Avecto/Automation/src/main/groovy/com/automation/pages/t
ime/ThreadSleeper.groovy: 11: Unknown type: METHOD_DEF at line: 11 c= olumn: 5. Fi
le: /D:/Development_Avecto/Automation/src/main/= groovy/com/automation/pages/time/
ThreadSleeper.groovy @ lin= e 11, column 5.
[ERROR] def =C2=A0sleeperWithAction() {
[ERROR] ^
[ERROR]
[ERROR] 1 error

=
But when I execute a test like this from Intellij it passes.

@Test( expected =3D SleepInterruptedException.class )
def void interruptedTest() {

Thread.<= span style=3D"font-style:italic">currentThread
().interrupt() def sleeper = =3D new Automatio= nSleeper( ms : <= span style=3D"color:rgb(0,0,255)">10)
sleeper.sleeper()
}<= /pre>
I am handling InterruptedException because some Selenium code =
calls sleep everywhere.
And the calling code isn't prepare=
d to be interrupted. Moreover there is no descriptive
message =
about what the thread is sleeping on. I plan to add some messages so that c=
ode that
calls my 'sleeper' will atleast have messages=
. The closure could help too.
Even selenium source code has th=
is section probably because that framework isn't required to deal with<=
/pre>
'InterruptedException'. It is a web scraping tool.

=
try {
= Thread.sleep(50);
} catch (Int= erruptedException e) {
throw new RuntimeException( e);
}


Thanks,
Mohan
<= br>
On 6 January 2018 at 03:47, Keith Suderman <s= uderman@anc.org> wrote:
What error are you = seeing?=C2=A0 Do you see the error at runtime or in your IDE?=C2=A0 Your co= de works for me (Groovy 2.4.9) so maybe check for unbalanced braces elsewhe= re in your code.

=
However, you shouldn= 't catch/rethrow the InterruptedException as you do. The InterruptedExc= eption is not thrown for "some reason", it is thrown when another= thread calls Thread.interrupt() on your thread (e.g. to wake your thread u= p so it can check its state).=C2=A0 For example:

Thread t =3D Thread= .start {
boolean running =3D true
while (r= unning) {
doSomeWork()
try {
Thread.sleep(1000)=C2=A0
= }
catch (Interrupt= edException e) {
running = =3D shouldIKeepRunning()
r= eturn true
}
}
}
// At program shutdown/cleanup
t.interrupt()
t.join()
println "Our thread has termintated."

The Closure passed to the Thread.sleep method can be used = in place of the try/catch block.=C2=A0 That is the closure will be called w= hen Thread.interrupt() is called on your thread i.e.:

Thread t =3D Thread.s= tart {
boolean running =3D false
while(running) {
= doSomeWork()
Thread.sleep= (1000) {
// Called then Thread.s= leep() is interrupted.
running = =3D false
return true
}
}
}
// ...
t.interrupt()
t.join()


=
Finally, if you are doing complicated threading work you should really= be using GPars or Java's Executors, ThreadPools, et al.

=
Cheers,
Keith

On Jan 5,= 2018, at 11:01 AM, Mohan Radhakrishnan <radhakrishnan.mohan@gmail.com&= gt; wrote:




Hi=
,
    =
     I am new to groovy. Here I tried to create
a simple wrapper around 'slee=
p'.
Thanks,
Mohan
=
/**
= * Our custom slee= p logic.
*/
trait ThreadSleeper {
long ms Closure cl = =3D {}

= /*Sleep with an action taken*/
def sleeperWithAction() {
try{

Thread.sleep ms, cl

= }catch= ( InterruptedException ie ){
throw new SleepInterruptedException( ie, "Thread.sleep is interrup= ted for "+
= "some reason = [" + ie.getMessage() +"]");
}
}


/*If there is no actio= n to be taken then we call this*/
def sleeper() {
try{

Thread.sleep ms

= }catch( InterruptedException ie ){
throw new SleepInterruptedException( ie, "Thread.sleep is inte= rrupted for "
+
= "some reas= on [" + ie.getMessage() +"]");
}
}
}
=

----------------------=
Keith Suderman
Research Associ= ate
Department of Computer Science
Vassar College, Poughkeepsie NY
=






--94eb2c08879292f43305623f5cd7--