Permalink
Browse files

Camera sensor queue is now optional.

  • Loading branch information...
hekonsek committed Apr 25, 2016
1 parent ecb55ba commit 40f86a133ca185fe0a2b46e7853989dbaf8a19f2
@@ -31,31 +31,37 @@ class CameraSensor extends RouteBuilder {
private final String deviceId
private final boolean sendToCloud
private final boolean enqueue
CameraSensor(IoTConnector connector, Raspistill raspistill, File workdir, String deviceId, boolean sendToCloud) {
private final boolean sendEnqueuedToCloud
CameraSensor(IoTConnector connector, Raspistill raspistill, File workdir, String deviceId,
boolean enqueue, boolean sendEnqueuedToCloud) {
this.connector = connector
this.raspistill = raspistill
this.workdir = workdir
this.deviceId = deviceId
this.sendToCloud = sendToCloud
this.enqueue = enqueue
this.sendEnqueuedToCloud = sendEnqueuedToCloud
}
@Override
void configure() {
workdir.mkdirs()
def queue = new File(workdir, 'queue')
queue.mkdirs()
raspistill.timelapse()
def queue = new File(workdir, 'queue')
queue.mkdirs()
from("file:${workdir.absolutePath}/?delay=250&noop=true&idempotent=false&fileName=camera.jpg").
to("file:${queue.absolutePath}?fileName=\${random(1,100000)}.jpg")
if(enqueue) {
from("file:${workdir.absolutePath}/?delay=250&noop=true&idempotent=false&fileName=camera.jpg").
to("file:${queue.absolutePath}?fileName=\${random(1,100000)}.jpg")
// Send enqueued image data to a cloud
if(sendToCloud) {
from("file:${queue.absolutePath}").process {
connector.toBus('camera.process', it.in.getBody(byte[].class), arguments(deviceId, 'eu'))
// Send enqueued image data to a cloud
if (sendEnqueuedToCloud) {
from("file:${queue.absolutePath}").process {
connector.toBus('camera.process', it.in.getBody(InputStream.class), arguments(deviceId, 'eu'))
}
}
}
}
@@ -34,8 +34,10 @@ class CameraSensorConfiguration {
@Bean
CameraSensor cameraSensor(IoTConnector connector, Raspistill raspistill,
@Value('${sensor.camera.workdir:/tmp/camera}') File workdir,
@Value('${deviceId}') String deviceId, @Value('${sensor.camera.sendToCloud:true}') boolean sendToCloud) {
new CameraSensor(connector, raspistill, workdir, deviceId, sendToCloud)
@Value('${deviceId}') String deviceId,
@Value('${sensor.camera.enqueue:true}') boolean enqueue,
@Value('${sensor.camera.sendEnqueuedToCloud:true}') boolean sendEnqueuedToCloud) {
new CameraSensor(connector, raspistill, workdir, deviceId, enqueue, sendEnqueuedToCloud)
}
@Bean
@@ -32,7 +32,7 @@ class CameraSensorConfigurationNoCloudTest extends CloudPlatformTest {
@Override
protected void beforeCloudPlatformStarted() {
setStringProperty('sensor.camera.workdir', Files.createTempDir().absolutePath)
setBooleanProperty('sensor.camera.sendToCloud', false)
setBooleanProperty('sensor.camera.sendEnqueuedToCloud', false)
}
@AfterClass
@@ -0,0 +1,55 @@
/**
* Licensed to the Rhiot under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The licenses this file to You 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 io.rhiot.gateway.sensors.camera.spring
import com.google.common.io.Files
import io.rhiot.cloudplatform.runtime.spring.test.CloudPlatformTest
import io.rhiot.gateway.sensors.camera.CameraSensor
import org.junit.AfterClass
import org.junit.Ignore
import org.junit.Test
import static com.google.common.truth.Truth.assertThat
import static io.rhiot.utils.Properties.*
class CameraSensorConfigurationNoEnqueueTest extends CloudPlatformTest {
@Override
protected void beforeCloudPlatformStarted() {
setStringProperty('sensor.camera.workdir', Files.createTempDir().absolutePath)
setBooleanProperty('sensor.camera.enqueue', false)
}
@AfterClass
static void afterClass() {
restoreSystemProperties()
}
@Test
void shouldSendSensorDataToConnector() {
// Given
def cameraSensor = cloudPlatform.applicationContext().getBean(CameraSensor.class)
Files.write('foo'.bytes, new File(cameraSensor.workdir, 'camera.jpg'))
// When
Thread.sleep(5000)
// Then
assertThat(new File(cameraSensor.workdir, 'queue').list().toList()).isEmpty()
}
}
@@ -27,13 +27,16 @@ import java.util.concurrent.Callable
import static com.google.common.truth.Truth.assertThat
import static com.jayway.awaitility.Awaitility.await
import static io.rhiot.cloudplatform.connector.Header.arguments
import static io.rhiot.utils.Properties.setBooleanProperty
import static io.rhiot.utils.Properties.setStringProperty
class CameraSensorConfigurationTest extends CloudPlatformTest {
@Override
protected void beforeCloudPlatformStarted() {
setStringProperty('sensor.camera.workdir', Files.createTempDir().absolutePath)
setBooleanProperty('sensor.camera.enqueue', true)
setBooleanProperty('sensor.camera.sendEnqueuedToCloud', true)
}
@Test

0 comments on commit 40f86a1

Please sign in to comment.