use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.
the class SimpleReactorService method processInstruction.
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public InstructionStatus processInstruction(Instruction instruction) {
// look for an existing status...
Instruction instr = instructionDao.getInstruction(instruction.getId(), instruction.getInstructorId());
if (instr == null) {
// persist new status
instructionDao.storeInstruction(instruction);
instr = instructionDao.getInstruction(instruction.getId(), instruction.getInstructorId());
}
return instr.getStatus();
}
use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.
the class CASettingsServiceTests method processUpdateSetting.
@Test
public void processUpdateSetting() throws IOException {
// GIVEN
dao.storeSetting(new Setting("foo", "bar", "bam", null));
Configuration config = EasyMock.createMock(Configuration.class);
mocks.add(config);
Hashtable<String, Object> configProps = new Hashtable<>();
expect(ca.getConfiguration("foo", null)).andReturn(config);
expect(config.getProperties()).andReturn(configProps).anyTimes();
Capture<Dictionary<String, ?>> configPropsCaptor = Capture.newInstance();
config.update(capture(configPropsCaptor));
// WHEN
replayAll();
Map<String, String> params = new LinkedHashMap<>(2);
params.put("key", "foo");
params.put("type", "bar");
params.put("value", "bam");
Instruction instr = createLocalInstruction(SettingsService.TOPIC_UPDATE_SETTING, params);
InstructionStatus result = service.processInstruction(instr);
// THEN
assertThat("Result provided", result, is(notNullValue()));
Map<String, ?> props = CollectionUtils.mapForDictionary(configPropsCaptor.getValue());
assertThat("Config updated", props, hasEntry("bar", "bam"));
assertThat("Config updated props", props.keySet(), hasSize(1));
}
use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.
the class CASettingsServiceTests method processUpdateSetting_noValue.
@Test
public void processUpdateSetting_noValue() throws IOException {
// GIVEN
expect(dao.deleteSetting("foo", "bar")).andReturn(true);
Configuration config = EasyMock.createMock(Configuration.class);
mocks.add(config);
Hashtable<String, Object> configProps = new Hashtable<>();
expect(ca.getConfiguration("foo", null)).andReturn(config);
expect(config.getProperties()).andReturn(configProps).anyTimes();
// WHEN
replayAll();
Map<String, String> params = new LinkedHashMap<>(2);
params.put("key", "foo");
params.put("type", "bar");
Instruction instr = createLocalInstruction(SettingsService.TOPIC_UPDATE_SETTING, params);
InstructionStatus result = service.processInstruction(instr);
// THEN
assertThat("Result provided", result, is(notNullValue()));
}
use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.
the class JdbcInstructionDaoTests method findForAck.
@Test
public void findForAck() {
storeNew();
List<Instruction> results = dao.findInstructionsForAcknowledgement();
assertThat("Result provided", results, hasSize(1));
assertEquals(lastDatum.getId(), results.get(0).getId());
// update ack now for second search
InstructionStatus newStatus = lastDatum.getStatus().newCopyWithAcknowledgedState(lastDatum.getStatus().getInstructionState());
dao.storeInstructionStatus(lastDatum.getId(), lastDatum.getInstructorId(), newStatus);
results = dao.findInstructionsForAcknowledgement();
assertThat("Result not found", results, hasSize(0));
}
use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.
the class JdbcInstructionDaoTests method compareAndSetStatus.
@Test
public void compareAndSetStatus() {
storeNew();
InstructionStatus execStatus = lastDatum.getStatus().newCopyWithState(InstructionState.Executing);
boolean updated = dao.compareAndStoreInstructionStatus(lastDatum.getId(), lastDatum.getInstructorId(), InstructionState.Received, execStatus);
assertThat("Status updated", updated, equalTo(true));
Instruction instr = dao.getInstruction(lastDatum.getId(), lastDatum.getInstructorId());
assertThat("State", instr.getStatus().getInstructionState(), equalTo(InstructionState.Executing));
assertThat("Acknoledged state", instr.getStatus().getAcknowledgedInstructionState(), is(nullValue()));
}
Aggregations