Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit deviceId check #520

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pubber/.idea/runConfigurations/Pubber.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pubber/src/main/java/daq/pubber/Pubber.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ private static void singularPubber(String[] args) throws InterruptedException {
return true;
});
} catch (Exception e) {
new RuntimeException("While starting singular pubber", e).printStackTrace();
if (pubber != null) {
pubber.terminate();
}
throw new RuntimeException("While starting singular pubber", e);
}
}

Expand Down Expand Up @@ -361,6 +361,10 @@ private void initializeDevice() {
if (configuration.endpoint == null) {
configuration.endpoint = siteModel.makeEndpointConfig(configuration.projectId, deviceId);
}
if (!siteModel.allDeviceIds().contains(configuration.deviceId)) {
throw new IllegalArgumentException(
"Device ID " + configuration.deviceId + " not found in site model");
}
processDeviceMetadata(siteModel.getMetadata(configuration.deviceId));
} else if (pubSubClient != null) {
pullDeviceMessage();
Expand Down
33 changes: 33 additions & 0 deletions pubber/src/test/java/daq/pubber/PubberTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package daq.pubber;

import com.google.common.collect.ImmutableList;
import java.util.List;
import org.junit.Test;

/**
* Unit tests for Pubber.
*/
public class PubberTest extends TestBase {

private static final String TEST_PROJECT = "test-project";
private static final String TEST_SITE = "../sites/udmi_site_model";
private static final String BAD_DEVICE = "ASHDQWHD";
private static final String SERIAL_NO = "18217398172";

@Test
public void missingDevice() {
try {
List<String> args = ImmutableList.of(TEST_PROJECT, TEST_SITE, BAD_DEVICE, SERIAL_NO);
Pubber.main(args.toArray(new String[0]));
} catch (Throwable e) {
while (e != null) {
String message = e.getMessage();
if (message.contains(BAD_DEVICE)) {
return;
}
e = e.getCause();
}
}
throw new RuntimeException("No exception thrown for bad device");
}
}
2 changes: 0 additions & 2 deletions pubber/src/test/java/daq/pubber/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import static daq.pubber.ListPublisher.getMessageString;

import org.checkerframework.checker.units.qual.A;
import udmi.schema.Auth_provider;
import udmi.schema.DiscoveryCommand;
import udmi.schema.EndpointConfiguration;
import udmi.schema.PubberConfiguration;
Expand Down