integration tests: in unloadAndKill, remove all segments if no date range given

This commit is contained in:
sahner 2015-12-02 11:40:59 -06:00
parent bad96537a9
commit ae4357dfab
5 changed files with 50 additions and 17 deletions

View File

@ -36,6 +36,7 @@ import org.joda.time.Interval;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Map; import java.util.Map;
import java.util.ArrayList;
public class CoordinatorResourceTestClient public class CoordinatorResourceTestClient
{ {
@ -64,11 +65,35 @@ public class CoordinatorResourceTestClient
); );
} }
private String getIntervalsURL(String dataSource)
{
return String.format("%sdatasources/%s/intervals", getCoordinatorURL(), dataSource);
}
private String getLoadStatusURL() private String getLoadStatusURL()
{ {
return String.format("%s%s", getCoordinatorURL(), "loadstatus"); return String.format("%s%s", getCoordinatorURL(), "loadstatus");
} }
// return a list of the segment dates for the specified datasource
public ArrayList<String> getSegmentIntervals(final String dataSource) throws Exception
{
ArrayList<String> segments = null;
try {
StatusResponseHolder response = makeRequest(HttpMethod.GET, getIntervalsURL(dataSource));
segments = jsonMapper.readValue(
response.getContent(), new TypeReference<ArrayList<String>>()
{
}
);
}
catch (Exception e) {
throw Throwables.propagate(e);
}
return segments;
}
private Map<String, Integer> getLoadStatus() private Map<String, Integer> getLoadStatus()
{ {
Map<String, Integer> status = null; Map<String, Integer> status = null;
@ -82,7 +107,7 @@ public class CoordinatorResourceTestClient
); );
} }
catch (Exception e) { catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
} }
return status; return status;
} }

View File

@ -31,6 +31,8 @@ import org.joda.time.Interval;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.ArrayList;
import java.util.Collections;
public abstract class AbstractIndexerTest public abstract class AbstractIndexerTest
{ {
@ -50,7 +52,17 @@ public abstract class AbstractIndexerTest
protected void unloadAndKillData(final String dataSource) throws Exception protected void unloadAndKillData(final String dataSource) throws Exception
{ {
unloadAndKillData (dataSource, "2013-01-01T00:00:00.000Z", "2013-12-01T00:00:00.000Z"); ArrayList<String> intervals = coordinator.getSegmentIntervals(dataSource);
// each element in intervals has this form:
// 2015-12-01T23:15:00.000Z/2015-12-01T23:16:00.000Z
// we'll sort the list (ISO dates have lexicographic order)
// then delete segments from the 1st date in the first string
// to the 2nd date in the last string
Collections.sort (intervals);
String first = intervals.get(0).split("/")[0];
String last = intervals.get(intervals.size() -1).split("/")[1];
unloadAndKillData (dataSource, first, last);
} }
protected void unloadAndKillData(final String dataSource, String start, String end) throws Exception protected void unloadAndKillData(final String dataSource, String start, String end) throws Exception

View File

@ -64,7 +64,7 @@ public class ITIndexerTest extends AbstractIndexerTest
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Throwables.propagate(e); throw Throwables.propagate(e);
} }
finally { finally {
unloadAndKillData(INDEX_DATASOURCE); unloadAndKillData(INDEX_DATASOURCE);

View File

@ -196,7 +196,7 @@ public class ITKafkaTest extends AbstractIndexerTest
producer.send(message); producer.send(message);
} }
catch (Exception ioe) { catch (Exception ioe) {
Throwables.propagate(ioe); throw Throwables.propagate(ioe);
} }
try { try {
@ -238,7 +238,7 @@ public class ITKafkaTest extends AbstractIndexerTest
try { try {
this.queryHelper.testQueriesFromString(queryStr, 2); this.queryHelper.testQueriesFromString(queryStr, 2);
} catch (Exception e) { } catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
} }
// wait for segments to be handed off // wait for segments to be handed off
@ -259,7 +259,7 @@ public class ITKafkaTest extends AbstractIndexerTest
); );
} }
catch (Exception e) { catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
} }
LOG.info("segments are present"); LOG.info("segments are present");
segmentsExist = true; segmentsExist = true;
@ -269,7 +269,7 @@ public class ITKafkaTest extends AbstractIndexerTest
this.queryHelper.testQueriesFromString(queryStr, 2); this.queryHelper.testQueriesFromString(queryStr, 2);
} }
catch (Exception e) { catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
} }
} }
@ -287,9 +287,7 @@ public class ITKafkaTest extends AbstractIndexerTest
// remove segments // remove segments
if (segmentsExist) { if (segmentsExist) {
try { try {
String first = DateTimeFormat.forPattern("yyyy-MM-dd'T00:00:00.000Z'").print(dtFirst); unloadAndKillData(DATASOURCE);
String last = DateTimeFormat.forPattern("yyyy-MM-dd'T00:00:00.000Z'").print(dtFirst.plusDays(1));
unloadAndKillData(DATASOURCE, first, last);
} }
catch (Exception e) { catch (Exception e) {
LOG.warn("exception while removing segments: [%s]", e.getMessage()); LOG.warn("exception while removing segments: [%s]", e.getMessage());

View File

@ -140,7 +140,7 @@ public class ITRealtimeIndexTaskTest extends AbstractIndexerTest
this.queryHelper.testQueriesFromString(getRouterURL(), queryStr, 2); this.queryHelper.testQueriesFromString(getRouterURL(), queryStr, 2);
} }
catch (Exception e) { catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
} }
// wait for the task to complete // wait for the task to complete
@ -166,12 +166,10 @@ public class ITRealtimeIndexTaskTest extends AbstractIndexerTest
this.queryHelper.testQueriesFromString(getRouterURL(), queryStr, 2); this.queryHelper.testQueriesFromString(getRouterURL(), queryStr, 2);
} }
catch (Exception e) { catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
} }
finally { finally {
String first = DateTimeFormat.forPattern("yyyy-MM-dd'T'00:00:00.000'Z'").print(dtFirst); unloadAndKillData(INDEX_DATASOURCE);
String last = DateTimeFormat.forPattern("yyyy-MM-dd'T'00:00:00.000'Z'").print(dtFirst.plusDays(1));
unloadAndKillData(INDEX_DATASOURCE, first, last);
} }
} }
@ -191,7 +189,7 @@ public class ITRealtimeIndexTaskTest extends AbstractIndexerTest
isr = new InputStreamReader(ITRealtimeIndexTaskTest.class.getResourceAsStream(EVENT_DATA_FILE)); isr = new InputStreamReader(ITRealtimeIndexTaskTest.class.getResourceAsStream(EVENT_DATA_FILE));
} }
catch (Exception e) { catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
} }
try { try {
reader = new BufferedReader(isr); reader = new BufferedReader(isr);
@ -243,7 +241,7 @@ public class ITRealtimeIndexTaskTest extends AbstractIndexerTest
} }
} }
catch (Exception e) { catch (Exception e) {
Throwables.propagate(e); throw Throwables.propagate(e);
} }
finally { finally {
reader.close(); reader.close();