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

Handle legacy state messages #710

Merged
merged 46 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
cdb0506
Adding model workflow script check
grafnu Aug 5, 2023
3fe1781
Fix
grafnu Aug 6, 2023
778aa32
More debugging
grafnu Aug 6, 2023
bbaed8c
Simplified version
grafnu Aug 6, 2023
f230a78
Updating site_model workdlow
grafnu Aug 6, 2023
5925e21
Rename
grafnu Aug 6, 2023
4d090f3
Merge remote-tracking branch 'faucet/master'
grafnu Aug 9, 2023
8ed1b9c
Initial failing test
grafnu Aug 9, 2023
e474def
Linty
grafnu Aug 9, 2023
af7dd77
Rename state file
grafnu Aug 9, 2023
e7e4aca
Merge branch 'master' into badstate
grafnu Aug 14, 2023
d47970c
Merge branch 'master' into badstate
grafnu Aug 16, 2023
ce3926d
Merge branch 'master' into badstate
grafnu Aug 18, 2023
8aa7418
Merge branch 'master' into badstate
grafnu Aug 18, 2023
eea9a57
Merge branch 'master' into badstate
grafnu Aug 19, 2023
92feafa
Merge branch 'master' into badstate
grafnu Aug 21, 2023
13f288c
Merge branch 'master' into badstate
grafnu Aug 21, 2023
2681bfc
Merge branch 'master' into badstate
grafnu Aug 22, 2023
a142a71
Merge branch 'master' into badstate
grafnu Aug 25, 2023
04e4b68
Merge branch 'master' into badstate
grafnu Aug 27, 2023
989eba7
Debugging fixes
grafnu Aug 28, 2023
d82d30b
FIxing timestamp
grafnu Aug 28, 2023
e0017e0
Merge branch 'master' into badstate
grafnu Aug 30, 2023
2eb2559
Test corrupt site model
grafnu Sep 4, 2023
9ae7386
Fix metadata error checking for pubber
grafnu Sep 4, 2023
a92709b
Move corruption to test_regclean
grafnu Sep 4, 2023
b3b7a39
Line length
grafnu Sep 4, 2023
bf92410
Fix error checking out
grafnu Sep 5, 2023
6f72ed5
Adding workflow_dispatch
grafnu Sep 5, 2023
6514a96
Fix some testing
grafnu Sep 5, 2023
790423f
Fix registrar tests
grafnu Sep 5, 2023
1ee68a1
Cleanup mangled device
grafnu Sep 5, 2023
1c7a7e2
Rename outputs
grafnu Sep 5, 2023
0cf0b25
Adjusting out
grafnu Sep 5, 2023
61f7e39
Merge branch 'master' into badstate
grafnu Sep 5, 2023
f07f811
Testing cleanup
grafnu Sep 5, 2023
43a2605
Merge branch 'master' into badstate
grafnu Sep 5, 2023
b47da1b
Fix things
grafnu Sep 5, 2023
25e99d6
Fix rerror map redaction
grafnu Sep 5, 2023
c4a0cc8
Do some cleanup for testing
grafnu Sep 5, 2023
6d11e85
Move message upgrader/downgrader
grafnu Sep 5, 2023
6f24f5b
Use MessageUpgrader
grafnu Sep 5, 2023
23ef5ee
Refactor message upgrader usage
grafnu Sep 5, 2023
ffc6302
Fix state test version
grafnu Sep 5, 2023
9884955
Keeping tests in not-shared directory
grafnu Sep 6, 2023
cb094cc
Make state test more comprehensive
grafnu Sep 6, 2023
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
3 changes: 3 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
run: bin/test_mosquitto
- name: bin/run_tests udmis_tests
run: bin/run_tests udmis_tests
- name: udmis test output
if: ${{ always() }}
run: more out/test_* | cat

unit:
name: Unit Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import com.google.bos.udmi.service.pod.UdmiServicePod;
import com.google.udmi.util.CleanDateFormat;
import java.io.File;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand All @@ -30,8 +28,27 @@ public abstract class ProcessorTestBase extends MessageTestBase {
public static final Date TEST_TIMESTAMP = CleanDateFormat.cleanDate();
public static final String TEST_FUNCTIONS = "functions-version";
protected final List<Object> captured = new ArrayList<>();
private ProcessorBase processor;
protected IotAccessBase provider;
private ProcessorBase processor;

/**
* Write a deployment file for testing.
*/
public static void writeVersionDeployFile() {
File deployFile = new File(ReflectProcessor.DEPLOY_FILE);
try {
deleteDirectory(deployFile.getParentFile());
deployFile.getParentFile().mkdirs();
SetupUdmiConfig deployedVersion = new SetupUdmiConfig();
deployedVersion.deployed_at = TEST_TIMESTAMP;
deployedVersion.deployed_by = TEST_USER;
deployedVersion.udmi_functions = TEST_FUNCTIONS;
deployedVersion.udmi_version = TEST_VERSION;
writeFile(deployedVersion, deployFile);
} catch (Exception e) {
throw new RuntimeException("While writing deploy file " + deployFile.getAbsolutePath(), e);
}
}

protected int getDefaultCount() {
return getMessageCount(Object.class);
Expand All @@ -45,6 +62,15 @@ protected int getMessageCount(Class<?> clazz) {
return processor.getMessageCount(clazz);
}

@NotNull
protected abstract Class<? extends ProcessorBase> getProcessorClass();

protected <T> T initializeTestInstance(@SuppressWarnings("unused") Class<T> clazz) {
initializeTestInstance();
//noinspection unchecked
return (T) processor;
}

protected void initializeTestInstance() {
try {
UdmiServicePod.resetForTest();
Expand All @@ -56,6 +82,15 @@ protected void initializeTestInstance() {
}
}

protected void terminateAndWait() {
getReverseDispatcher().terminate();
getTestDispatcher().awaitShutdown();
getTestDispatcher().terminate();
getReverseDispatcher().awaitShutdown();
provider.shutdown();
processor.shutdown();
}

private void activateReverseProcessor() {
MessageDispatcherImpl reverseDispatcher = getReverseDispatcher();
reverseDispatcher.registerHandler(Object.class, this::resultHandler);
Expand All @@ -76,37 +111,6 @@ private void createProcessorInstance() {
provider.activate();
}

/**
* Write a deployment file for testing.
*/
public static void writeVersionDeployFile() {
File deployFile = new File(ReflectProcessor.DEPLOY_FILE);
try {
deleteDirectory(deployFile.getParentFile());
deployFile.getParentFile().mkdirs();
SetupUdmiConfig deployedVersion = new SetupUdmiConfig();
deployedVersion.deployed_at = TEST_TIMESTAMP;
deployedVersion.deployed_by = TEST_USER;
deployedVersion.udmi_functions = TEST_FUNCTIONS;
deployedVersion.udmi_version = TEST_VERSION;
writeFile(deployedVersion, deployFile);
} catch (Exception e) {
throw new RuntimeException("While writing deploy file " + deployFile.getAbsolutePath(), e);
}
}

@NotNull
protected abstract Class<? extends ProcessorBase> getProcessorClass();

protected void terminateAndWait() {
getReverseDispatcher().terminate();
getTestDispatcher().awaitShutdown();
getTestDispatcher().terminate();
getReverseDispatcher().awaitShutdown();
provider.shutdown();
processor.shutdown();
}

private void resultHandler(Object message) {
captured.add(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.google.udmi.util.GeneralUtils.ifNotNullGet;
import static com.google.udmi.util.JsonUtil.fromStringStrict;
import static com.google.udmi.util.JsonUtil.loadFileRequired;
import static com.google.udmi.util.JsonUtil.stringify;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand All @@ -14,6 +15,8 @@

import com.google.bos.udmi.service.messaging.impl.MessageBase.Bundle;
import com.google.udmi.util.CleanDateFormat;
import com.google.udmi.util.GeneralUtils;
import com.google.udmi.util.JsonUtil;
import java.util.Date;
import java.util.function.Function;
import org.jetbrains.annotations.NotNull;
Expand All @@ -34,6 +37,7 @@
public class StateProcessorTest extends ProcessorTestBase {

public static final Date INITIAL_LAST_START = CleanDateFormat.cleanDate(new Date(12981837));
private static final String BAD_STATE_MESSAGE_FILE = "src/test/messages/bad_state.json";

@NotNull
protected Class<? extends ProcessorBase> getProcessorClass() {
Expand Down Expand Up @@ -136,6 +140,12 @@ public void multiExpansion() {
assertEquals(1, getDefaultCount(), "default handler count");
}

@Test
public void badMessage() {
StateProcessor processor = initializeTestInstance(StateProcessor.class);
processor.defaultHandler(loadFileRequired(Object.class, BAD_STATE_MESSAGE_FILE));
}

/**
* Test that a state update with one sub-block results in a received message of the proper type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.google.bos.udmi.service.core.ProcessorBase.REFLECT_REGISTRY;
import static com.google.udmi.util.JsonUtil.toMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.times;
Expand Down
1 change: 1 addition & 0 deletions udmis/src/test/messages/bad_state.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename legacy_state.json

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"timestamp":"2023-08-08T16:32:31.000Z","version":"1","system":{"last_config":"2023-08-08T13:07:00Z","operational":true,"serial_no":"30000852","hardware":{"make":"EasyIO","model":"FS32","sku":"PLACEHOLDER","rev":"PLACEHOLDER"},"software":{"firmware":"V3.0b53"}},"pointset":{"points":{"temperature_sensor":{"units":"Degrees-Celsius"}}}}
Loading