use of com.canoo.dp.impl.client.legacy.communication.CommandAndHandler in project dolphin-platform by canoo.
the class BlindCommandBatcherTest method doMaxBatchSize.
public void doMaxBatchSize() {
// given:
batcher.setMaxBatchSize(4);
ArrayList<CommandAndHandler> list = new ArrayList<CommandAndHandler>();
for (int i = 0; i < 17; i++) {
list.add(new CommandAndHandler(null));
}
// when:
for (CommandAndHandler commandAndHandler : list) {
batcher.batch(commandAndHandler);
}
// then:
try {
Assert.assertEquals(4, batcher.getWaitingBatches().getVal().size());
Assert.assertEquals(4, batcher.getWaitingBatches().getVal().size());
Assert.assertEquals(4, batcher.getWaitingBatches().getVal().size());
Assert.assertEquals(4, batcher.getWaitingBatches().getVal().size());
Assert.assertEquals(1, batcher.getWaitingBatches().getVal().size());
Assert.assertTrue(batcher.isEmpty());
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.canoo.dp.impl.client.legacy.communication.CommandAndHandler in project dolphin-platform by canoo.
the class BlindCommandBatcherTest method testMergeCreatePmAfterValueChange.
@Test
public void testMergeCreatePmAfterValueChange() {
// given:
batcher.setMergeValueChanges(true);
List<CommandAndHandler> list = new ArrayList<CommandAndHandler>();
ValueChangedCommand command = new ValueChangedCommand();
command.setAttributeId("0");
command.setNewValue(1);
list.add(new CommandAndHandler(command));
list.add(new CommandAndHandler(new CreatePresentationModelCommand()));
// when:
for (CommandAndHandler commandAndHandler : list) {
batcher.batch(commandAndHandler);
}
// then:
try {
List<CommandAndHandler> nextBatch = batcher.getWaitingBatches().getVal();
Assert.assertEquals(2, nextBatch.size());
Assert.assertEquals(ValueChangedCommand.class, nextBatch.get(0).getCommand().getClass());
Assert.assertEquals(CreatePresentationModelCommand.class, nextBatch.get(1).getCommand().getClass());
Assert.assertTrue(batcher.isEmpty());
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.canoo.dp.impl.client.legacy.communication.CommandAndHandler in project dolphin-platform by canoo.
the class BlindCommandBatcherTest method doMultipleBlindsAreBatched.
public void doMultipleBlindsAreBatched() {
Assert.assertTrue(batcher.isEmpty());
List<CommandAndHandler> list = Arrays.asList(new CommandAndHandler(null), new CommandAndHandler(null), new CommandAndHandler(null));
for (CommandAndHandler commandAndHandler : list) {
batcher.batch(commandAndHandler);
}
try {
Assert.assertEquals(list, batcher.getWaitingBatches().getVal());
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.canoo.dp.impl.client.legacy.communication.CommandAndHandler in project dolphin-platform by canoo.
the class BlindCommandBatcherTest method testMergeInOneCommand.
@Test
public void testMergeInOneCommand() {
// given:
batcher.setMergeValueChanges(true);
List<CommandAndHandler> list = new ArrayList<CommandAndHandler>();
ValueChangedCommand command = new ValueChangedCommand();
command.setAttributeId("0");
command.setNewValue(1);
list.add(new CommandAndHandler(command));
ValueChangedCommand command1 = new ValueChangedCommand();
command1.setAttributeId("0");
command1.setNewValue(2);
list.add(new CommandAndHandler(command1));
ValueChangedCommand command2 = new ValueChangedCommand();
command2.setAttributeId("0");
command2.setNewValue(3);
list.add(new CommandAndHandler(command2));
// when:
for (CommandAndHandler commandAndHandler : list) {
batcher.batch(commandAndHandler);
}
// then:
try {
List<CommandAndHandler> nextBatch = batcher.getWaitingBatches().getVal();
Assert.assertEquals(1, nextBatch.size());
Assert.assertEquals(ValueChangedCommand.class, nextBatch.get(0).getCommand().getClass());
ValueChangedCommand cmd = (ValueChangedCommand) nextBatch.get(0).getCommand();
Assert.assertEquals(3, cmd.getNewValue());
Assert.assertTrue(batcher.isEmpty());
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.canoo.dp.impl.client.legacy.communication.CommandAndHandler in project dolphin-platform by canoo.
the class BlindCommandBatcherTest method doNonBlindForcesBatch.
public void doNonBlindForcesBatch() {
Assert.assertTrue(batcher.isEmpty());
List<CommandAndHandler> list = new ArrayList<CommandAndHandler>();
list.add(new CommandAndHandler(null));
list.add(new CommandAndHandler(null));
list.add(new CommandAndHandler(null));
list.add(new CommandAndHandler(null, new OnFinishedHandler() {
@Override
public void onFinished() {
}
}));
for (CommandAndHandler commandAndHandler : list) {
batcher.batch(commandAndHandler);
}
Assert.assertEquals(4, ((ArrayList<CommandAndHandler>) list).size());
try {
Assert.assertEquals(list.subList(0, 3), batcher.getWaitingBatches().getVal());
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
try {
Assert.assertEquals(Collections.singletonList(list.get(3)), batcher.getWaitingBatches().getVal());
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations