setup:
  - do:
      indices.create:
        index: airline-data
        body:
          mappings:
            properties:
              time:
                type: date
              airline:
                type: keyword
              responsetime:
                type: float
              event_rate:
                type: integer
  - do:
      transform.put_transform:
        transform_id: "airline-transform-stats-continuous"
        body: >
          {
            "source": { "index": "airline-data" },
            "dest": { "index": "airline-data-by-airline-stats-continuous" },
            "pivot": {
              "group_by": { "airline": {"terms": {"field": "airline"}}},
              "aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
            },
            "sync": { "time": { "field": "time", "delay": "1m" } }
          }
  - do:
      transform.start_transform:
        transform_id: "airline-transform-stats-continuous"

---
teardown:
  - do:
      transform.stop_transform:
        wait_for_checkpoint: false
        transform_id: "airline-transform-stats-continuous"
        wait_for_completion: true

  - do:
      transform.delete_transform:
        transform_id: "airline-transform-stats-continuous"

---
"Test get continuous transform stats":
  - do:
      transform.get_transform_stats:
        transform_id: "airline-transform-stats-continuous"
  - match: { count: 1 }
  - match: { transforms.0.id: "airline-transform-stats-continuous" }
  # Since this is continuous, there is no worry of it automatically stopping
  - match: { transforms.0.state: "/started|indexing/" }
  - lte: { transforms.0.checkpointing.last.checkpoint: 1 }
  # Since this is continuous, and _start does not return until it is assigned
  # we should see a node assignment
  - is_true: transforms.0.node
  - is_true: transforms.0.node.id
  - is_true: transforms.0.node.name
  - is_true: transforms.0.node.ephemeral_id
  - is_true: transforms.0.node.transport_address
  - lte: { transforms.0.stats.pages_processed: 1 }
  - match: { transforms.0.stats.documents_processed: 0 }
  - match: { transforms.0.stats.documents_indexed: 0 }
  - lte: { transforms.0.stats.trigger_count: 1 }
  - match: { transforms.0.stats.index_time_in_ms: 0 }
  - match: { transforms.0.stats.index_total: 0 }
  - match: { transforms.0.stats.index_failures: 0 }
  - gte: { transforms.0.stats.search_time_in_ms: 0 }
  - lte: { transforms.0.stats.search_total: 1 }
  - match: { transforms.0.stats.search_failures: 0 }
  - is_true: transforms.0.stats.exponential_avg_checkpoint_duration_ms
  - match: { transforms.0.stats.exponential_avg_documents_indexed: 0.0 }
  - match: { transforms.0.stats.exponential_avg_documents_processed: 0.0 }
