Skip to content

Instantly share code, notes, and snippets.

@dav-rob
Created November 30, 2011 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dav-rob/1409236 to your computer and use it in GitHub Desktop.
Save dav-rob/1409236 to your computer and use it in GitHub Desktop.
Base Recreation Class and Test Class
public class BaseErrorRecreation {
protected static int waitForServerTimeout = 15000;
public static final Logger LOG = Logger.getLogger(BaseErrorRecreation.class.getName());
protected static Client client;
protected static boolean initializing = false;
protected static boolean initialized = false;
/*
* Spring properties Follow
*/
protected static String clusterName = "CMTDev2";
protected static String host = "166.15.121.116";
protected static String hosts = "166.15.121.116:9300,166.15.121.116:9301,169.49.110.160:9300,169.49.110.160:9301,169.49.110.160:9302,169.49.110.160:9303,169.49.110.160:9304";
protected static String multicast = "false";
public static void init() {
if (initializing){
throw new IllegalStateException("Already initializing");
}
initializing = true;
LOG.info("\n*****************************************\n" +
"clusteName[" + clusterName + "]\n" +
"multicast[" + multicast + "]\n" +
"host[" + host + "]\n" +
"hosts[" + hosts + "]\n" +
"*****************************************");
Builder fixedSettings = ImmutableSettings.settingsBuilder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 1)
.put("cluster.name", clusterName)
.put("node.client", true )
.put("index.mapper", "dynamic:false")
.put("node.data", false);
boolean doMulticast = Boolean.getBoolean(multicast);
if (doMulticast){
fixedSettings.put("discovery.zen.ping.multicast.enabled", true);
} else {
fixedSettings.put("network.host", host)
.put("discovery.zen.ping.unicast.enabled", true)
.put("http.enabled", true)
.put("discovery.zen.ping.unicast.hosts", hosts)
.put("discovery.zen.ping.multicast.enabled", false);
}
Settings settings = fixedSettings.build();
LOG.info("\n******************* Settings **********************\n" +
settings.getAsMap() + "\n" +
"****************************************************");
LOG.info("Before Node build for cluster[" + clusterName + "]");
Node hostNode = NodeBuilder.nodeBuilder()
.loadConfigSettings(false)
.settings(settings)
.node()
.start();
LOG.info("After Node build for cluster[" + clusterName + "]");
//CSUtils.print(settings.getAsMap(), "Elastic Search Client Settings", LOG);
Client methodLocalClient = hostNode.client();
LOG.info("Testing Health and Readiness of Cluster[" + clusterName + "]");
ClusterHealthResponse serverStatus = methodLocalClient.admin().cluster().prepareHealth()
.setWaitForYellowStatus()
.setTimeout(new TimeValue(waitForServerTimeout))
.execute().actionGet();
if (serverStatus.isTimedOut()){
throw new RuntimeException("No Index Server Found");
}
LOG.info("Cluster[" + clusterName + "] health is good, connected.");
client = methodLocalClient;
initialized = true;
}
protected static String[] getIndices(){
ClusterStateResponse clusterStateResponse = getClusterState();
String[] indices = clusterStateResponse.getState().getMetaData().concreteAllIndices();
return indices;
}
protected static ClusterStateResponse getClusterState() {
ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
ClusterStateResponse clusterStateResponse = client.admin().cluster().state(clusterStateRequest).actionGet();
return clusterStateResponse;
}
protected static void printAllIndicies(String desc, String[] indices) {
StringBuilder builder = new StringBuilder("\n" + desc + ", All Indexes[");
for (String index : indices){
builder.append(index + ",");
}
builder.append("]");
LOG.info("" + indices.length + " indices: " + builder.toString());
}
protected static int printIndexesAndReturnLength(String message) {
if (message == null){
message = "Number of Indexes = ";
}
String[] indices = getIndices();
int initialLen = indices.length;
printAllIndicies(message, indices);
return initialLen;
}
public static void deleteIndex(String indexName){
if (indexName == null){
LOG.info("Index Name is Null !!. Returning.");
return;
}
LOG.info("Before delete index name [" + indexName + "]");
DeleteIndexRequest deleteIndexReq = new DeleteIndexRequest(indexName);
try {
client.admin().indices().delete(deleteIndexReq)
.actionGet();
} catch (Exception e) {
LOG.info("Exception thrown while deleting index, this may not be fatal, please check.");
return;
}
LOG.info("Delete index[" + indexName + "] finished");
}
protected static void createIndexWithTypeAndMapping(String indexName, String indexType, String typeMapping) {
CreateIndexRequestBuilder createIndexReq = client.admin().indices().prepareCreate(indexName);
createIndexReq.addMapping(indexType, typeMapping);
createIndexReq.execute().actionGet();
}
protected static void queryAll(String indexName) {
Timer timer = Timer.startTimer();
SearchResponse searchResponse = client.prepareSearch()
.setIndices(indexName)
.setQuery(QueryBuilders.matchAllQuery()) //.addSort("party_id", SortOrder.ASC)
.setFrom(0)
.setSize(500)
.execute().actionGet();
timer.endTimer("Time for " + indexName + " query in ms = ");
System.out.println("Response hit count = " + searchResponse.getHits().getTotalHits());
}
protected static void addToIndex(String indexName, String indexType, String json, String id) {
IndexResponse postResponse = client.prepareIndex()
.setIndex(indexName)
.setType(indexType)
.setId(id)
.setSource(json)
.setRefresh(true)
.execute().actionGet();
}
protected static class Timer {
private Date startDate;
private Date endDate;
public static Timer startTimer() {
Timer timer = new Timer();
timer.startDate = new Date();
return timer;
}
public long endTimer(){
String message = "Time taken in milliseconds = ";
return endTimer(message);
}
/**
* Set message == null for no output.
*
* @param message
* @return
*/
public long endTimer(String message) {
if (this.startDate == null){
throw new IllegalStateException("Not initialised");
}
this.endDate = new Date();
long millis = this.endDate.getTime() - this.startDate.getTime();
if (message != null){
LOG.info(message + millis + "ms");
}
startDate = null;
endDate = null;
return millis;
}
}
}
public class RecreateWeekViewError extends BaseErrorRecreation {
public static void main(String[] args) throws InterruptedException{
init();
String hashMapIndexName = "hmindex";
String hashMapIndexType = "hmtype";
String hashMapTypeMapping = "{\"" + hashMapIndexType + "\": {\"dynamic\": \"false\",\"properties\": {\"phone\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"nja_mgmt_access\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"person_name\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"barePhoneNumber\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"global_research\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"listIds\": {\"type\": \"integer\"},\"japan_research\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"myLatestActivitiesJson\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"vote_survey_status_t\": {\"type\": \"string\"},\"europe_eq_rank\": {\"null_value\": 99999999,\"type\": \"integer\"},\"sc_segmentation\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"mainEmail\": {\"type\": \"string\"},\"userIds\": {\"type\": \"integer\"},\"tokenisedCompanyId\": {\"type\": \"string\"},\"nja_research\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"weekViewMap\": {\"enabled\": false,\"type\": \"object\"},\"nja_eq_rank\": {\"null_value\": 99999999,\"type\": \"integer\"},\"person_last_name\": {\"type\": \"string\"},\"created_by\": {\"type\": \"string\"},\"europe_segmentation\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"position_t\": {\"type\": \"string\"},\"nja_asia_tier\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"mobile_displaynum\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"kam\": {\"type\": \"boolean\"},\"person_first_name_lc\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"companyName\": {\"type\": \"string\"},\"primary_company_name\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"country\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"latestActivityParticipantName_t\": {\"type\": \"string\"},\"email\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"region_t\": {\"type\": \"string\"},\"surveys\": {\"properties\": {\"vote_survey_start_date\": {\"format\": \"dateOptionalTime\",\"type\": \"date\"},\"vote_survey_type_desc\": {\"type\": \"string\"},\"vote_survey_end_date\": {\"format\": \"dateOptionalTime\",\"type\": \"date\"}}},\"nja_holt_bespoke\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"reserveLatestActivityBy\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"person_last_name_lc\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"region\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"position\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"mobile_displaynum_t\": {\"type\": \"string\"},\"latestActivityParticipantId\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"jobTitle_t\": {\"type\": \"string\"},\"japan_execution\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"latestActivityParticipantName\": {\"null_value\": \"zzzzzz\",\"analyzer\": \"sortable\",\"type\": \"string\"},\"internationalCode\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"id\": {\"type\": \"integer\"},\"displayAddress\": {\"type\": \"string\"},\"japan_holt_bespoke\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"myLatestActivities\": {\"properties\": {\"userId\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"date\": {\"format\": \"dateOptionalTime\",\"type\": \"date\"}},\"type\": \"nested\"},\"n_america_eq_rank\": {\"null_value\": 99999999,\"type\": \"integer\"},\"global_eq_rank\": {\"null_value\": 99999999,\"type\": \"integer\"},\"person_first_name\": {\"type\": \"string\"},\"gescId\": {\"format\": \"dateOptionalTime\",\"type\": \"date\"},\"jobTitle\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"nja_execution\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"emerging_emea_segmentation\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"vote_survey_status\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"areaCode\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"country_t\": {\"type\": \"string\"},\"latestActivityDate\": {\"format\": \"yyyy-MM-dd HH:mm:ss\",\"type\": \"date\"},\"reserveLatestActivityDate\": {\"format\": \"yyyy-MM-dd HH:mm:ss\",\"type\": \"date\"},\"us_segmentation\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"japan_asia_tier\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"japan_mgmt_access\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"faxDisplayNumber\": {\"type\": \"string\"},\"phone_t\": {\"type\": \"string\"},\"address\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"partyTypeCode\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"us_execution\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"fullName\": {\"type\": \"string\"},\"companyId\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"domain_type\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"salutation\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"australia_research\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"entity_type_code\": {\"type\": \"integer\"},\"customColumns\": {\"properties\": {\"valueLC\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"ccId\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"value\": {\"type\": \"string\"}},\"type\": \"nested\"}}}}";
String hashMapDataFormatString = "{\"listIds\": [%d,5148,9229,9498,9499,9500,9501,12322,13848,14234,65000108,65000565,65000817,65001359,65001902,65002339,65003328,65004019,65004339,65004765,65005204,65005630,65005645,65010448,65011359,65012559,65015664,65015677,65015678,65015679,65015680,65015681],\"myLatestActivitiesJson\": \"{\\\"25090877\\\":\\\"2011-01-11 19:57:00.0\\\",\\\"25281369\\\":\\\"2011-05-20 10:30:00.0\\\",\\\"25290023\\\":\\\"2011-09-14 15:00:00.0\\\",\\\"25687073\\\":\\\"2010-04-07 12:00:00.0\\\",\\\"25081143\\\":\\\"2010-01-12 11:00:00.0\\\",\\\"25084075\\\":\\\"2009-12-07 14:55:00.0\\\",\\\"25019158\\\":\\\"2011-09-07 09:08:00.0\\\",\\\"25441734\\\":\\\"2011-08-25 08:33:00.0\\\",\\\"25550794\\\":\\\"2011-08-11 08:20:00.0\\\",\\\"25809346\\\":\\\"2010-07-12 10:59:00.0\\\",\\\"25411678\\\":\\\"2011-08-25 08:33:00.0\\\",\\\"65008107\\\":\\\"2011-08-10 14:12:00.0\\\",\\\"25393489\\\":\\\"2007-10-18 09:54:00.0\\\",\\\"25540824\\\":\\\"2010-01-13 09:43:00.0\\\"}\",\"sc_segmentation\": \"Small Cap HT\",\"userIds\": [],\"tokenisedCompanyId\": 34,\"weekViewMap\": {\"20120130-day4\": {\"numActivities\": 1,\"userTypeMap\": {\"25448024\": \"T\"}},\"20111219-day2\": {\"numActivities\": 3,\"userTypeMap\": {\"25867415\": \"M\",\"25448024\": \"E\"}}},\"nja_eq_rank\": \"146\",\"europe_segmentation\": \"IM A\",\"position_t\": \"Analyst\",\"kam\": false,\"country\": \"United States\",\"position\": \"Analyst\",\"region\": \"AMER\",\"latestActivityParticipantId\": \"51979\",\"internationalCode\": \"1\",\"id\": 65103767,\"n_america_eq_rank\": \"150\",\"global_eq_rank\": \"177\",\"gescId\": 22,\"latestActivityDate\": \"2011-09-14 15:00:00\",\"areaCode\": \"212\",\"country_t\": \"United States\",\"us_segmentation\": \"SMC\",\"partyTypeCode\": -2,\"companyId\": 34,\"us_execution\": \"2\",\"salutation\": \"Dear Fayad\",\"entity_type_code\": -2}";
String noHMIndexName = "index";
String noHMIndexType = "notype";
String noHMTypeMapping = "{\"" + noHMIndexType + "\": {\"dynamic\": \"false\",\"properties\": {\"phone\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"nja_mgmt_access\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"person_name\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"barePhoneNumber\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"global_research\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"listIds\": {\"type\": \"integer\"},\"japan_research\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"myLatestActivitiesJson\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"vote_survey_status_t\": {\"type\": \"string\"},\"europe_eq_rank\": {\"null_value\": 99999999,\"type\": \"integer\"},\"sc_segmentation\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"mainEmail\": {\"type\": \"string\"},\"userIds\": {\"type\": \"integer\"},\"tokenisedCompanyId\": {\"type\": \"string\"},\"nja_research\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"nja_eq_rank\": {\"null_value\": 99999999,\"type\": \"integer\"},\"person_last_name\": {\"type\": \"string\"},\"created_by\": {\"type\": \"string\"},\"europe_segmentation\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"position_t\": {\"type\": \"string\"},\"nja_asia_tier\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"mobile_displaynum\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"kam\": {\"type\": \"boolean\"},\"person_first_name_lc\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"companyName\": {\"type\": \"string\"},\"primary_company_name\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"country\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"latestActivityParticipantName_t\": {\"type\": \"string\"},\"email\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"region_t\": {\"type\": \"string\"},\"surveys\": {\"properties\": {\"vote_survey_start_date\": {\"format\": \"dateOptionalTime\",\"type\": \"date\"},\"vote_survey_type_desc\": {\"type\": \"string\"},\"vote_survey_end_date\": {\"format\": \"dateOptionalTime\",\"type\": \"date\"}}},\"nja_holt_bespoke\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"reserveLatestActivityBy\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"person_last_name_lc\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"region\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"position\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"mobile_displaynum_t\": {\"type\": \"string\"},\"latestActivityParticipantId\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"jobTitle_t\": {\"type\": \"string\"},\"japan_execution\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"latestActivityParticipantName\": {\"null_value\": \"zzzzzz\",\"analyzer\": \"sortable\",\"type\": \"string\"},\"internationalCode\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"id\": {\"type\": \"integer\"},\"displayAddress\": {\"type\": \"string\"},\"japan_holt_bespoke\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"myLatestActivities\": {\"properties\": {\"userId\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"date\": {\"format\": \"dateOptionalTime\",\"type\": \"date\"}},\"type\": \"nested\"},\"n_america_eq_rank\": {\"null_value\": 99999999,\"type\": \"integer\"},\"global_eq_rank\": {\"null_value\": 99999999,\"type\": \"integer\"},\"person_first_name\": {\"type\": \"string\"},\"gescId\": {\"format\": \"dateOptionalTime\",\"type\": \"date\"},\"jobTitle\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"nja_execution\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"emerging_emea_segmentation\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"vote_survey_status\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"areaCode\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"country_t\": {\"type\": \"string\"},\"latestActivityDate\": {\"format\": \"yyyy-MM-dd HH:mm:ss\",\"type\": \"date\"},\"reserveLatestActivityDate\": {\"format\": \"yyyy-MM-dd HH:mm:ss\",\"type\": \"date\"},\"us_segmentation\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"japan_asia_tier\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"japan_mgmt_access\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"faxDisplayNumber\": {\"type\": \"string\"},\"phone_t\": {\"type\": \"string\"},\"address\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"partyTypeCode\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"us_execution\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"fullName\": {\"type\": \"string\"},\"companyId\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"domain_type\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"salutation\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"australia_research\": {\"analyzer\": \"sortable\",\"type\": \"string\"},\"entity_type_code\": {\"type\": \"integer\"},\"customColumns\": {\"properties\": {\"valueLC\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"ccId\": {\"index\": \"not_analyzed\",\"type\": \"string\"},\"value\": {\"type\": \"string\"}},\"type\": \"nested\"}}}}";
String noHMDataFormatString = "{\"listIds\": [%d,5148,9229,9498,9499,9500,9501,12322,13848,14234,65000108,65000565,65000817,65001359,65001902,65002339,65003328,65004019,65004339,65004765,65005204,65005630,65005645,65010448,65011359,65012559,65015664,65015677,65015678,65015679,65015680,65015681],\"myLatestActivitiesJson\": \"{\\\"25090877\\\":\\\"2011-01-11 19:57:00.0\\\",\\\"25281369\\\":\\\"2011-05-20 10:30:00.0\\\",\\\"25290023\\\":\\\"2011-09-14 15:00:00.0\\\",\\\"25687073\\\":\\\"2010-04-07 12:00:00.0\\\",\\\"25081143\\\":\\\"2010-01-12 11:00:00.0\\\",\\\"25084075\\\":\\\"2009-12-07 14:55:00.0\\\",\\\"25019158\\\":\\\"2011-09-07 09:08:00.0\\\",\\\"25441734\\\":\\\"2011-08-25 08:33:00.0\\\",\\\"25550794\\\":\\\"2011-08-11 08:20:00.0\\\",\\\"25809346\\\":\\\"2010-07-12 10:59:00.0\\\",\\\"25411678\\\":\\\"2011-08-25 08:33:00.0\\\",\\\"65008107\\\":\\\"2011-08-10 14:12:00.0\\\",\\\"25393489\\\":\\\"2007-10-18 09:54:00.0\\\",\\\"25540824\\\":\\\"2010-01-13 09:43:00.0\\\"}\",\"sc_segmentation\": \"Small Cap HT\",\"userIds\": [],\"tokenisedCompanyId\": 34,\"nja_eq_rank\": \"146\",\"europe_segmentation\": \"IM A\",\"position_t\": \"Analyst\",\"kam\": false,\"country\": \"United States\",\"position\": \"Analyst\",\"region\": \"AMER\",\"latestActivityParticipantId\": \"51979\",\"internationalCode\": \"1\",\"id\": 65103767,\"n_america_eq_rank\": \"150\",\"global_eq_rank\": \"177\",\"gescId\": 22,\"latestActivityDate\": \"2011-09-14 15:00:00\",\"areaCode\": \"212\",\"country_t\": \"United States\",\"us_segmentation\": \"SMC\",\"partyTypeCode\": -2,\"companyId\": 34,\"us_execution\": \"2\",\"salutation\": \"Dear Fayad\",\"entity_type_code\": -2}";
createIndexAddDocsAndQuery(hashMapIndexName, hashMapIndexType, hashMapTypeMapping, hashMapDataFormatString);
createIndexAddDocsAndQuery(noHMIndexName, noHMIndexType, noHMTypeMapping, noHMDataFormatString);
//cleanup
//_this.client.admin().indices().prepareDelete(indexName).execute().actionGet();
}
private static void createIndexAddDocsAndQuery(String hashMapIndexName,
String hashMapIndexType, String hashMapTypeMapping,
String hashMapDataFormatString) throws InterruptedException {
int lenBefore = printIndexesAndReturnLength("Indexes Before Create");
createIndexWithTypeAndMapping(hashMapIndexName, hashMapIndexType, hashMapTypeMapping);
Thread.sleep(1000);
int lenAfterCreate = printIndexesAndReturnLength("Indexes After Create");
assert lenAfterCreate == lenBefore + 1;
// Add 3,000 documents, spread across 2 known lists with 1500 documents in each list.// ~600 per min using one-at-a-time indexing over network to NY.
int count = 0;
for (int j=0; j < 1500; j++){
for (int i = 1; i <= 2; i++){
count++;
String json = String.format(hashMapDataFormatString, i);
addToIndex(hashMapIndexName, hashMapIndexType, json, "" + count);
}
if (count % 500 == 0){
LOG.info("Indexed " + count + " documents.");
}
}
queryAll(hashMapIndexName);
deleteIndex(hashMapIndexName);
Thread.sleep(1000);
int lenAfterDelete = printIndexesAndReturnLength("Indexes After Delete");
assert lenAfterDelete == lenBefore;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment