/*
 * Copyright 2013 Google Inc. All Rights Reserved.
 * 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.google.appengine.tck.taskqueue;

import static junit.framework.Assert.assertEquals;

import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.QueueStatistics;

import org.jboss.arquillian.junit.Arquillian;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
 */
@RunWith(Arquillian.class)
public class StatsTest extends QueueTestBase {

    /**
     * Because the stats processing is approximate, this test only verifies the basics.
     */
    @Test
    public void testStatsApiBasic() throws Exception {
        final Queue queue = QueueFactory.getQueue("pull-queue");
        QueueStatistics stats = queue.fetchStatistics();
        Assert.assertNotNull(stats);
        Assert.assertEquals("pull-queue", stats.getQueueName());
        assertEquals(1.0, stats.getEnforcedRate());

        Assert.assertTrue(stats.getNumTasks() >= 0);
        Assert.assertTrue(stats.getExecutedLastMinute() >= 0);
        Assert.assertTrue(stats.getOldestEtaUsec() == null || stats.getOldestEtaUsec() >= 0);
        Assert.assertTrue(stats.getRequestsInFlight() >= 0);
    }
}

@@ -654,60 +654,8 @@
 e;%0A%0A
-import static junit.framework.Assert.assertEquals;%0A%0A
 impo
@@ -699,16 +699,16 @@
 .Queue;%0A
+
 import c
@@ -1013,16 +1013,81 @@
 tin%3C/a%3E%0A
+ * @author %3Ca href=%22mailto:terryok@google.com%22%3ETerry Okamoto%3C/a%3E%0A
  */%0A@Run
@@ -1253,16 +1253,70 @@
 basics.%0A
+     * The dev_appserver generates random statistics.%0A
      */%0A
@@ -1616,26 +1616,26 @@
     
-a
+A
 ssert
-Equals(1.0, 
+.assertTrue(
 stat
@@ -1653,16 +1653,21 @@
 edRate()
+ %3E= 0
 );%0A%0A    

Make enforcedRate() check flexible to handle the random dev_appserver stats generated.