Mritunjay Mritunjay - 14 days ago 5
Java Question

Speed Up Spring MockMvc Integration Test with Embedded Cassandra

We are using MockMvc Framework to test Spring Controllers with JUnit. Controller returns a

DefferedResult
.

The
mockmvc.perform
looks like bellow

mockMvc.perform(post("/customer")
.accept(APPLICATION_JSON)
.header(AUTH_TOKEN_KEY, "xyz")
.header(FROM_KEY, "email@gmail.com")
.content(json)
.contentType(APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(request().asyncStarted());


And it takes a lot of time. We are Using embedded cassandra and because of that it takes a lot of time.

I tried this as well, but it's same.

MvcResult mvcResult = mockMvc.perform(post("/customer")
.accept(APPLICATION_JSON)
.header(AUTH_TOKEN_KEY, "xyz")
.header(FROM_KEY, "email@gmail.com")
.content(json)
.contentType(APPLICATION_JSON))
.andReturn();

mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().isOk())
.andExpect(request().asyncStarted());


I've hundreds of tests, because of which the build process is really slow.

Is there a way, using JUnit I can say perform the request and wait for response in another thread to assert the results, Or anyother good way of speeding it up.

Thanks

Answer

As I mentioned in my question We are Using embedded cassandra and because of that it takes a lot of time.

I tried looking things in cassandra.yaml file and changed the line below.

commitlog_sync_batch_window_in_ms: 90

to

commitlog_sync_batch_window_in_ms: 1

That's all and the build time was reduced from 30 minutes to 2 minutes.

From cassandra.yaml comments:-

It will wait up to commitlog_sync_batch_window_in_ms milliseconds for other writes, before performing the sync.

After reducing this time the wait time was reduced and build time got reduced.

Comments