Skip to content

Commit

Permalink
integration tests: in unloadAndKill, remove all segments if no date r…
Browse files Browse the repository at this point in the history
…ange given
  • Loading branch information
rasahner committed Dec 8, 2015
1 parent bad9653 commit ae4357d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
import java.util.ArrayList;

public class CoordinatorResourceTestClient
{
Expand Down Expand Up @@ -64,11 +65,35 @@ private String getCoordinatorURL()
);
}

private String getIntervalsURL(String dataSource)
{
return String.format("%sdatasources/%s/intervals", getCoordinatorURL(), dataSource);
}

private String getLoadStatusURL()
{
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()
{
Map<String, Integer> status = null;
Expand All @@ -82,7 +107,7 @@ private Map<String, Integer> getLoadStatus()
);
}
catch (Exception e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}
return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Callable;
import java.util.ArrayList;
import java.util.Collections;

public abstract class AbstractIndexerTest
{
Expand All @@ -50,7 +52,17 @@ public abstract class AbstractIndexerTest

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testIndexData() throws Exception
}
catch (Exception e) {
e.printStackTrace();
Throwables.propagate(e);
throw Throwables.propagate(e);
}
finally {
unloadAndKillData(INDEX_DATASOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void testKafka()
producer.send(message);
}
catch (Exception ioe) {
Throwables.propagate(ioe);
throw Throwables.propagate(ioe);
}

try {
Expand Down Expand Up @@ -238,7 +238,7 @@ public void testKafka()
try {
this.queryHelper.testQueriesFromString(queryStr, 2);
} catch (Exception e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}

// wait for segments to be handed off
Expand All @@ -259,7 +259,7 @@ public Boolean call() throws Exception
);
}
catch (Exception e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}
LOG.info("segments are present");
segmentsExist = true;
Expand All @@ -269,7 +269,7 @@ public Boolean call() throws Exception
this.queryHelper.testQueriesFromString(queryStr, 2);
}
catch (Exception e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}
}

Expand All @@ -287,9 +287,7 @@ public void afterClass()
// remove segments
if (segmentsExist) {
try {
String first = DateTimeFormat.forPattern("yyyy-MM-dd'T00:00:00.000Z'").print(dtFirst);
String last = DateTimeFormat.forPattern("yyyy-MM-dd'T00:00:00.000Z'").print(dtFirst.plusDays(1));
unloadAndKillData(DATASOURCE, first, last);
unloadAndKillData(DATASOURCE);
}
catch (Exception e) {
LOG.warn("exception while removing segments: [%s]", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void testRealtimeIndexTask() throws Exception
this.queryHelper.testQueriesFromString(getRouterURL(), queryStr, 2);
}
catch (Exception e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}

// wait for the task to complete
Expand All @@ -166,12 +166,10 @@ public Boolean call() throws Exception
this.queryHelper.testQueriesFromString(getRouterURL(), queryStr, 2);
}
catch (Exception e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}
finally {
String first = DateTimeFormat.forPattern("yyyy-MM-dd'T'00:00:00.000'Z'").print(dtFirst);
String last = DateTimeFormat.forPattern("yyyy-MM-dd'T'00:00:00.000'Z'").print(dtFirst.plusDays(1));
unloadAndKillData(INDEX_DATASOURCE, first, last);
unloadAndKillData(INDEX_DATASOURCE);
}
}

Expand All @@ -191,7 +189,7 @@ public void postEvents() throws Exception
isr = new InputStreamReader(ITRealtimeIndexTaskTest.class.getResourceAsStream(EVENT_DATA_FILE));
}
catch (Exception e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}
try {
reader = new BufferedReader(isr);
Expand Down Expand Up @@ -243,7 +241,7 @@ public void postEvents() throws Exception
}
}
catch (Exception e) {
Throwables.propagate(e);
throw Throwables.propagate(e);
}
finally {
reader.close();
Expand Down

0 comments on commit ae4357d

Please sign in to comment.