serial-executor-service

Testing utility implementation of ScheduledExecutorService

License

License

GroupId

GroupId

org.logicalshift
ArtifactId

ArtifactId

serial-executor-service
Last Version

Last Version

1.3
Release Date

Release Date

Type

Type

jar
Description

Description

serial-executor-service
Testing utility implementation of ScheduledExecutorService
Source Code Management

Source Code Management

http://github.com/markkent/serial-executor-service/tree/master

Download serial-executor-service

How to add to project

<!-- https://jarcasting.com/artifacts/org.logicalshift/serial-executor-service/ -->
<dependency>
    <groupId>org.logicalshift</groupId>
    <artifactId>serial-executor-service</artifactId>
    <version>1.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.logicalshift/serial-executor-service/
implementation 'org.logicalshift:serial-executor-service:1.3'
// https://jarcasting.com/artifacts/org.logicalshift/serial-executor-service/
implementation ("org.logicalshift:serial-executor-service:1.3")
'org.logicalshift:serial-executor-service:jar:1.3'
<dependency org="org.logicalshift" name="serial-executor-service" rev="1.3">
  <artifact name="serial-executor-service" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.logicalshift', module='serial-executor-service', version='1.3')
)
libraryDependencies += "org.logicalshift" % "serial-executor-service" % "1.3"
[org.logicalshift/serial-executor-service "1.3"]

Dependencies

compile (1)

Group / Artifact Type Version
com.google.guava : guava jar 12.0

test (1)

Group / Artifact Type Version
org.testng : testng jar 6.2.1

Project Modules

There are no modules declared in this project.

serial-executor-service

Test utility implementation of ScheduledExecutorService

Allows for testing of code such as the following:

class Foo
{
    private int count = 0;

    public Foo(ScheduledExecutorService service, Bar bar)
    {
        service.scheduleAtFixedRate(new Runnable()
            {
                @Override
                public void run()
                {
                    count++;
                    bar.doWhatever();
                }
            }, 5, 10, TimeUnit.SECONDS);
    }

    public int getCount()
    {
        return count;
    }
}

Without the capabilities of this utility, testing the above would require doing something like the following:

@Test
public void testFoo()
{
    Bar bar = new Bar();
    Foo foo = new Foo(Executors.newSingleThreadExecutor(), bar);

    Thread.sleep(5*1000);

    assertEquals(foo.getCount(), 1);
    assertTrue(bar.whateverGotDone());
}

Using this test class, the sleep is no longer required:

@Test
public void testFoo()
{
    SerialScheduledExecutorService executor = new SerialScheduledExecutorService();
    Bar bar = new Bar();
    Foo foo = new Foo(executor, bar);

    executor.elapseTime(5, TimeUnit.SECONDS);

    assertEquals(foo.getCount(), 1);
    assertTrue(bar.whateverGotDone());
}

For more examples, see the unit tests provided.

Versions

Version
1.3
1.2
1.1
1.0