Search code examples
javahadoopjunitapache-pigrule

Junit External Resource @Rule Order


I want to use multiple external resources in my test class, but I have a problem with ordering of external resources.

Here is code snippet :

public class TestPigExternalResource {

     // hadoop external resource, this should start first
     @Rule
     public HadoopSingleNodeCluster cluster = new HadoopSingleNodeCluster();

     // pig external resourcem, this should wait until hadoop external resource starts
     @Rule
     public  PigExternalResource pigExternalResource = new PigExternalResource(); 

     ...  
}

The problem is it tries to start pig before hadoop started, therefore I could not connect local hadoop single node cluster.

Is there any way to order rules of junit?

thanks


Solution

  • You can use RuleChain.

    @Rule
    public TestRule chain= RuleChain.outerRule(new HadoopSingleNodeCluster())
                               .around(new PigExternalResource());