Search code examples
javaunit-testingkuduapache-kudu

How can I configure the Kudu test harness to avoid "Block cache capacity exceeds the memory pressure threshold"


I am trying to follow the guide to using the KuduTestHarness in the Getting Started guide. I have created the following simple test case.

import org.apache.kudu.test.KuduTestHarness;

import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;

public class DemoTest{
    @Rule
    public KuduTestHarness harness=new KuduTestHarness();

    @Test
    public void testDemo(){
    assertTrue(true);
    }
}

But I get the following errors in the console log.

2020-10-07 11:50:01,060 [cluster stderr printer] INFO  org.apache.kudu.test.cluster.MiniKuduCluster - E1007 11:50:01.059237 17257 block_cache.cc:99] Block cache capacity exceeds the memory pressure threshold (536870912 bytes vs. 498776800 bytes). This will cause instability and harmful flushing behavior. Lower --block_cache_capacity_mb or raise --memory_limit_hard_bytes.

2020-10-07 11:50:01,060 [cluster stderr printer] INFO  org.apache.kudu.test.cluster.MiniKuduCluster - E1007 11:50:01.059262 17257 flags.cc:441] Detected inconsistency in command-line flags; exiting

2020-10-07 11:50:01,100 [main] DEBUG org.apache.kudu.test.cluster.MiniKuduCluster - Response: error {
  code: RUNTIME_ERROR
  message: "failed to start masters: Unable to start Master at index 0: /tmp/kudu-binary-jar1893943400146501302/kudu-binary-1.13.0-linux-x86_64/bin/kudu-master: process exited with non-zero status 1"
}

I tried adding a flag to the base builder, but it does not have any affect. The new flag does not show up in the list of flags in the logs.

import org.apache.kudu.test.cluster.MiniKuduCluster.MiniKuduClusterBuilder;
...
    static{
    MiniKuduClusterBuilder builder=KuduTestHarness.getBaseClusterBuilder();
    builder.addMasterServerFlag("--block_cache_capacity_mb=498776800");
    }
...

Can someone point me in the right direction for correctly configuring the test harness.


Solution

  • OK, I managed to solve this myself by reading the source code. I was puzzled by why the relevant javdocs for the MiniKuduCluster were not online.

    The answer is that getBaseClusterBuilder() is a factory method, not an accessor method as I had assumed. You get a new one every time and the test harness class will use a fresh builder when you create a new rule instance, so you need to inject your custom builder at that point. There is a constructor that takes the builder object.

    This code shows how it can be done.

        public static MiniKuduClusterBuilder builder;
    
        @BeforeClass
        public static void classInit(){
        builder=KuduTestHarness.getBaseClusterBuilder()
            .addMasterServerFlag("--block_cache_capacity_mb=475")
            .addTabletServerFlag("--block_cache_capacity_mb=475");
        }
    
        @Rule
        public KuduTestHarness harness=new KuduTestHarness(builder);
    

    The underlying problem was due to using a VM on my laptop with limited memory. There was not much I could do to get around that so the ability to customise the builder at this point is very useful.