arquillian / arquillian-spacelift

Arquillian process and package manager. Makes executing an external process or fetching platform depends dependencies an easier job
4 stars 7 forks source link

Why does Spacelift execute the given task twice a second? #31

Closed vinsguru closed 6 years ago

vinsguru commented 7 years ago

I would like to schedule a task to get executed once every second.

ConsoleWriterTool

public class ConsoleWriterTool extends Task<Object, Boolean>{

    private String txt;
    private int counter;
    private int limit = 10;

    public ConsoleWriterTool usingTxt(String txt) {
        this.txt = txt;
        return this;
    }

    public ConsoleWriterTool usingLimit(int limit) {
        this.limit = limit;
        return this;
    }

    @Override
    protected Boolean process(Object arg0) throws Exception {
        System.out.println(txt + " :: " + LocalDateTime.now() + " :: " + counter++);
        return counter > this.limit;
    }
}

Spacelift:


    Spacelift.task(ConsoleWriterTool.class)
            .usingTxt("Guru")
            .usingLimit(20)
            .execute()
            .reexecuteEvery(1, TimeUnit.SECONDS)
            .until(10, TimeUnit.SECONDS, new ExecutionCondition < Boolean > () {

                @Override
                public boolean satisfiedBy(Boolean limitReached) throws ExecutionException {
                    return limitReached;
                }

            });

Output:

Guru :: 2017-05-13T10:03:25.447 :: 0
Guru :: 2017-05-13T10:03:26.439 :: 1
Guru :: 2017-05-13T10:03:26.498 :: 2
Guru :: 2017-05-13T10:03:27.440 :: 3
Guru :: 2017-05-13T10:03:27.500 :: 4
Guru :: 2017-05-13T10:03:28.441 :: 5
Guru :: 2017-05-13T10:03:28.501 :: 6
Guru :: 2017-05-13T10:03:29.442 :: 7
Guru :: 2017-05-13T10:03:29.502 :: 8
Guru :: 2017-05-13T10:03:30.443 :: 9
Guru :: 2017-05-13T10:03:30.503 :: 10
Guru :: 2017-05-13T10:03:31.444 :: 11
Guru :: 2017-05-13T10:03:31.504 :: 12
Guru :: 2017-05-13T10:03:32.445 :: 13
Guru :: 2017-05-13T10:03:32.505 :: 14
Guru :: 2017-05-13T10:03:33.446 :: 15
Guru :: 2017-05-13T10:03:33.506 :: 16
Guru :: 2017-05-13T10:03:34.448 :: 17
Guru :: 2017-05-13T10:03:34.508 :: 18
Guru :: 2017-05-13T10:03:35.449 :: 19

Why does it execute twice a second? Is this a bug?

lordofthejars commented 7 years ago

We will need to check it out what's happening. Thank you very much for reporting. Of course if you find the problem feel free to send a PR, we are more than happy to receive these kind of contributions.

MatousJobanek commented 7 years ago

Hi, this could solve the issue: https://github.com/arquillian/arquillian-spacelift/pull/32

vinsguru commented 7 years ago

@MatousJobanek ,

Tried with Spacelift 1.0.1. Unfortunately this issue still exists. :(

smiklosovic commented 7 years ago

Hey @vinsguru

how is that possible?

Here you see the test case (1). If it was executed twice, would not that be the case that such test fail?

(1) https://github.com/arquillian/arquillian-spacelift/blob/master/spacelift-impl/src/test/java/org/arquillian/spacelift/task/execution/ExecutionCountTest.java

MatousJobanek commented 7 years ago

Hi, I guess that it is because Spacelift 1.0.1 was released before this fix - it's not contained there. To verify that it is really fixed clone this repo, install it into your local repository and use that one...

vinsguru commented 6 years ago

Works fine with 1.0.2