/**
 * Copyright 2013 BlackLocus
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.blacklocus.qs.worker.es;

import com.blacklocus.jres.BaseJresTest;
import com.blacklocus.jres.request.index.JresRefresh;
import com.blacklocus.jres.request.search.JresSearch;
import com.blacklocus.jres.response.search.JresSearchReply;
import com.blacklocus.qs.worker.QSLogService;
import com.blacklocus.qs.worker.model.QSLogTaskModel;
import com.blacklocus.qs.worker.model.QSLogTickModel;
import com.blacklocus.qs.worker.model.QSLogWorkerModel;
import com.google.common.collect.ImmutableMap;
import org.junit.Assert;
import org.junit.Test;

public class ElasticSearchQSLogServiceTest extends BaseJresTest {

    @Test
    public void testLifecycle() {
        QSLogService logService = new ElasticSearchQSLogService("test", jres);

        QSLogWorkerModel logWorker = new QSLogWorkerModel("test_worker", 0L);

        QSLogTaskModel logTask = new QSLogTaskModel("test_batch", "test_task", "test_handler",
                ImmutableMap.of("whatwhat?", "watch southpark"), "test_worker", 0L, null, null, false);
        logService.startedTask(logTask);

        logWorker.tick = 123L;
        logService.workerHeartbeat(logWorker);

        logService.logTask(new QSLogTickModel(logTask.taskId, "test worker", System.currentTimeMillis(), "log message 1"));
        logService.logTask(new QSLogTickModel(logTask.taskId, "test worker", System.currentTimeMillis(), "log message 2"));

        logTask.finishedHappy = true;
        logTask.finished = 5L;
        logTask.elapsed = logTask.finished - logTask.started;
        logService.completedTask(logTask);

        logWorker.tick = 456L;
        logService.workerHeartbeat(logWorker);


        jres.quest(new JresRefresh("test"));
        JresSearchReply reply = jres.quest(new JresSearch());
        Assert.assertEquals(new Integer(4), reply.getHits().getTotal()); // weak test
    }
}

@@ -1251,16 +1251,100 @@
 cle() %7B%0A
+        String index = %22ElasticSearchQSLogServiceTest.testLifecycle%22.toLowerCase();%0A
         
@@ -1399,22 +1399,21 @@
 Service(
-%22test%22
+index
 , jres);
@@ -2356,14 +2356,13 @@
 esh(
-%22test%22
+index
 ));%0A
@@ -2419,16 +2419,27 @@
 sSearch(
+index, null
 ));%0A    

fix unit test, isolate testing index