|
| 1 | +/* |
| 2 | + * This software is licensed under the GNU Affero General Public License, quoted below. |
| 3 | + * |
| 4 | + * This file is a part of PowerAPI. |
| 5 | + * |
| 6 | + * Copyright (C) 2011-2016 Inria, University of Lille 1. |
| 7 | + * |
| 8 | + * PowerAPI is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of |
| 11 | + * the License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * PowerAPI is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with PowerAPI. |
| 20 | + * |
| 21 | + * If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. |
| 22 | + */ |
| 23 | +package org.powerapi.reporter |
| 24 | + |
| 25 | +import java.util.UUID |
| 26 | + |
| 27 | +import scala.concurrent.duration.DurationInt |
| 28 | +import collection.JavaConversions._ |
| 29 | + |
| 30 | +import akka.util.Timeout |
| 31 | + |
| 32 | +import org.influxdb.dto.Query |
| 33 | +import org.joda.time.{DateTimeZone, DateTime} |
| 34 | +import org.powerapi.UnitTest |
| 35 | +import org.powerapi.core.power._ |
| 36 | +import org.powerapi.core.target.{Application, Process, Target} |
| 37 | + |
| 38 | +class InfluxDisplaySuite extends UnitTest { |
| 39 | + |
| 40 | + val timeout = Timeout(10.seconds) |
| 41 | + |
| 42 | + override def afterAll() = { |
| 43 | + system.shutdown() |
| 44 | + } |
| 45 | + |
| 46 | + "An InfluxDisplay" should "write an AggPowerReport message in a database" in { |
| 47 | + val muid = UUID.randomUUID() |
| 48 | + val timestamp = System.currentTimeMillis() |
| 49 | + val targets = Set[Target](Application("firefox"), Process(1), Process(2)) |
| 50 | + val devices = Set[String]("cpu", "gpu", "ssd") |
| 51 | + val power = 10.W |
| 52 | + |
| 53 | + val influxDisplay = new InfluxDisplay("http://localhost:8086", "powerapi", "powerapi", "test", "event.powerapi") |
| 54 | + influxDisplay.influxdb.createDatabase("test") |
| 55 | + influxDisplay.display(muid, timestamp, targets, devices, power) |
| 56 | + val query = new Query("SELECT * FROM \"event.powerapi\"", "test") |
| 57 | + val result = influxDisplay.influxdb.query(query) |
| 58 | + result.getResults.head.getSeries.head.getValues.head should contain theSameElementsAs Seq(s"${new DateTime(timestamp, DateTimeZone.UTC)}", s"$muid", devices.mkString(","), targets.mkString(","), s"${power.toMilliWatts}") |
| 59 | + influxDisplay.influxdb.deleteDatabase("test") |
| 60 | + } |
| 61 | +} |
| 62 | + |
0 commit comments