Feature horizontal scalability (#305)
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
committed by
Kai Zimmermann
parent
07cb62a3dd
commit
866bc72114
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter;
|
||||
import org.eclipse.hawkbit.repository.event.TenantAwareEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.junit.Before;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
|
||||
import org.springframework.cloud.bus.jackson.BusJacksonAutoConfiguration;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.MutableMessageHeaders;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.converter.AbstractMessageConverter;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
public abstract class AbstractRemoteEventTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private BusProtoStuffMessageConverter busProtoStuffMessageConverter;
|
||||
|
||||
private AbstractMessageConverter jacksonMessageConverter;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
final BusJacksonAutoConfiguration autoConfiguration = new BusJacksonAutoConfiguration();
|
||||
this.jacksonMessageConverter = autoConfiguration.busJsonConverter();
|
||||
ReflectionTestUtils.setField(jacksonMessageConverter, "packagesToScan",
|
||||
new String[] { "org.eclipse.hawkbit.repository.event.remote",
|
||||
ClassUtils.getPackageName(RemoteApplicationEvent.class) });
|
||||
((InitializingBean) jacksonMessageConverter).afterPropertiesSet();
|
||||
|
||||
}
|
||||
|
||||
private Message<?> createProtoStuffMessage(final TenantAwareEvent event) {
|
||||
final Map<String, Object> headers = Maps.newLinkedHashMap();
|
||||
headers.put(MessageHeaders.CONTENT_TYPE, BusProtoStuffMessageConverter.APPLICATION_BINARY_PROTOSTUFF);
|
||||
return busProtoStuffMessageConverter.toMessage(event, new MutableMessageHeaders(headers));
|
||||
}
|
||||
|
||||
private Message<String> createJsonMessage(final Object event) {
|
||||
final Map<String, MimeType> headers = Maps.newLinkedHashMap();
|
||||
headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
|
||||
try {
|
||||
final String json = new ObjectMapper().writeValueAsString(event);
|
||||
final Message<String> message = MessageBuilder.withPayload(json).copyHeaders(headers).build();
|
||||
return message;
|
||||
} catch (final JsonProcessingException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Message<?> createMessageWithImmutableHeader(final TenantAwareEvent event) {
|
||||
final Map<String, Object> headers = Maps.newLinkedHashMap();
|
||||
return busProtoStuffMessageConverter.toMessage(event, new MessageHeaders(headers));
|
||||
}
|
||||
|
||||
protected TenantAwareEvent createJacksonEvent(final TenantAwareEvent event) {
|
||||
final Message<?> message = createJsonMessage(event);
|
||||
return (TenantAwareEvent) jacksonMessageConverter.fromMessage(message, event.getClass());
|
||||
}
|
||||
|
||||
protected TenantAwareEvent createProtoStuffEvent(final TenantAwareEvent event) {
|
||||
final Message<?> message = createProtoStuffMessage(event);
|
||||
return (TenantAwareEvent) busProtoStuffMessageConverter.fromMessage(message, event.getClass());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Entity Id Events")
|
||||
public class RemoteIdEventTest extends AbstractRemoteEventTest {
|
||||
|
||||
private static final long ENTITY_ID = 1L;
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the is ds id correct reloaded")
|
||||
public void testDistributionSetDeletedEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetDeletedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the ds tag id is correct reloaded")
|
||||
public void testDistributionSetTagDeletedEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetTagDeletedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the target id is correct reloaded")
|
||||
public void testTargetDeletedEvent() {
|
||||
assertAndCreateRemoteEvent(TargetDeletedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the target tag id is correct reloaded")
|
||||
public void testTargetTagDeletedEvent() {
|
||||
assertAndCreateRemoteEvent(TargetTagDeletedEvent.class);
|
||||
}
|
||||
|
||||
protected void assertAndCreateRemoteEvent(final Class<? extends RemoteIdEvent> eventType) {
|
||||
|
||||
final Constructor<?> constructor = Arrays.stream(eventType.getDeclaredConstructors())
|
||||
.filter(con -> con.getParameterCount() == 3).findAny()
|
||||
.orElseThrow(() -> new IllegalArgumentException("Given event is not RemoteIdEvent compatible"));
|
||||
|
||||
try {
|
||||
final RemoteIdEvent event = (RemoteIdEvent) constructor.newInstance("tenant", ENTITY_ID, "Node");
|
||||
assertEntity(ENTITY_ID, event);
|
||||
} catch (final ReflectiveOperationException e) {
|
||||
fail("Exception should not happen " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected RemoteIdEvent assertEntity(final long id, final RemoteIdEvent event) {
|
||||
assertThat(event.getEntityId()).isSameAs(id);
|
||||
|
||||
RemoteIdEvent underTestCreatedEvent = (RemoteIdEvent) createProtoStuffEvent(event);
|
||||
assertThat(underTestCreatedEvent.getEntityId()).isEqualTo(id);
|
||||
|
||||
underTestCreatedEvent = (RemoteIdEvent) createJacksonEvent(event);
|
||||
assertThat(underTestCreatedEvent.getEntityId()).isEqualTo(id);
|
||||
|
||||
return underTestCreatedEvent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Test;
|
||||
import org.springframework.messaging.converter.MessageConversionException;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RemoteTenantAwareEvent Tests")
|
||||
public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that a immutable header is not work")
|
||||
public void testMessageWithImmutableHeader() {
|
||||
final DownloadProgressEvent downloadProgressEvent = new DownloadProgressEvent("DEFAULT", 3L, "Node");
|
||||
|
||||
try {
|
||||
createMessageWithImmutableHeader(downloadProgressEvent);
|
||||
fail("MessageConversionException should happen");
|
||||
} catch (final MessageConversionException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the download progress reloading by remote events works")
|
||||
public void reloadDownloadProgessByRemoteEvent() {
|
||||
final DownloadProgressEvent downloadProgressEvent = new DownloadProgressEvent("DEFAULT", 3L, "Node");
|
||||
|
||||
DownloadProgressEvent remoteEvent = (DownloadProgressEvent) createProtoStuffEvent(downloadProgressEvent);
|
||||
assertThat(downloadProgressEvent).isEqualTo(remoteEvent);
|
||||
|
||||
remoteEvent = (DownloadProgressEvent) createJacksonEvent(downloadProgressEvent);
|
||||
assertThat(downloadProgressEvent).isEqualTo(remoteEvent);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that target assignment event works")
|
||||
public void testTargetAssignDistributionSetEvent() {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final JpaAction generateAction = (JpaAction) entityFactory.generateAction();
|
||||
generateAction.setActionType(ActionType.FORCED);
|
||||
final Target generateTarget = entityFactory.generateTarget("Test");
|
||||
final Target target = targetManagement.createTarget(generateTarget);
|
||||
generateAction.setTarget(target);
|
||||
generateAction.setDistributionSet(dsA);
|
||||
final Action action = actionRepository.save(generateAction);
|
||||
|
||||
final TargetAssignDistributionSetEvent assignmentEvent = new TargetAssignDistributionSetEvent(action,
|
||||
serviceMatcher.getServiceId());
|
||||
|
||||
TargetAssignDistributionSetEvent underTest = (TargetAssignDistributionSetEvent) createProtoStuffEvent(
|
||||
assignmentEvent);
|
||||
assertTargetAssignDistributionSetEvent(action, underTest);
|
||||
|
||||
underTest = (TargetAssignDistributionSetEvent) createJacksonEvent(assignmentEvent);
|
||||
assertTargetAssignDistributionSetEvent(action, underTest);
|
||||
}
|
||||
|
||||
private void assertTargetAssignDistributionSetEvent(final Action action,
|
||||
final TargetAssignDistributionSetEvent underTest) {
|
||||
assertThat(underTest.getActionId()).isNotNull();
|
||||
assertThat(underTest.getControllerId()).isNotNull();
|
||||
assertThat(underTest.getDistributionSetId()).isNotNull();
|
||||
|
||||
assertThat(underTest.getActionId()).isEqualTo(action.getId());
|
||||
assertThat(underTest.getControllerId()).isEqualTo(action.getTarget().getControllerId());
|
||||
assertThat(underTest.getDistributionSetId()).isEqualTo(action.getDistributionSet().getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.AbstractRemoteEventTest;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Entity Events")
|
||||
public abstract class AbstractRemoteEntityEventTest<E> extends AbstractRemoteEventTest {
|
||||
|
||||
protected RemoteEntityEvent<?> assertAndCreateRemoteEvent(final Class<? extends RemoteEntityEvent<?>> eventType) {
|
||||
final E baseEntity = createEntity();
|
||||
final RemoteEntityEvent<?> event = createRemoteEvent(baseEntity, eventType);
|
||||
assertEntity(baseEntity, event);
|
||||
return event;
|
||||
}
|
||||
|
||||
protected RemoteEntityEvent<?> createRemoteEvent(final E baseEntity,
|
||||
final Class<? extends RemoteEntityEvent<?>> eventType) {
|
||||
|
||||
Constructor<?> constructor = null;
|
||||
for (final Constructor<?> constructors : eventType.getDeclaredConstructors()) {
|
||||
if (constructors.getParameterCount() == 2) {
|
||||
constructor = constructors;
|
||||
}
|
||||
}
|
||||
|
||||
if (constructor == null) {
|
||||
throw new IllegalArgumentException("No suitable constructor foundes");
|
||||
}
|
||||
|
||||
try {
|
||||
return (RemoteEntityEvent<?>) constructor.newInstance(baseEntity, "Node");
|
||||
} catch (final ReflectiveOperationException e) {
|
||||
fail("Exception should not happen " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected RemoteEntityEvent<?> assertEntity(final E baseEntity, final RemoteEntityEvent<?> event) {
|
||||
assertThat(event.getEntity()).isSameAs(baseEntity);
|
||||
|
||||
RemoteEntityEvent<?> underTestCreatedEvent = (RemoteEntityEvent<?>) createProtoStuffEvent(event);
|
||||
assertThat(underTestCreatedEvent.getEntity()).isEqualTo(baseEntity);
|
||||
|
||||
underTestCreatedEvent = (RemoteEntityEvent<?>) createJacksonEvent(event);
|
||||
assertThat(underTestCreatedEvent.getEntity()).isEqualTo(baseEntity);
|
||||
return underTestCreatedEvent;
|
||||
}
|
||||
|
||||
protected abstract E createEntity();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Test ActionCreatedEvent and ActionUpdatedEvent")
|
||||
public class ActionEventTest extends AbstractRemoteEntityEventTest<Action> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the action entity reloading by remote created works")
|
||||
public void testActionCreatedEvent() {
|
||||
assertAndCreateRemoteEvent(ActionCreatedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the action entity reloading by remote updated works")
|
||||
public void testActionUpdatedEvent() {
|
||||
assertAndCreateRemoteEvent(ActionUpdatedEvent.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Action createEntity() {
|
||||
final JpaAction generateAction = (JpaAction) entityFactory.generateAction();
|
||||
generateAction.setActionType(ActionType.FORCED);
|
||||
final Target generateTarget = entityFactory.generateTarget("Test");
|
||||
final Target target = targetManagement.createTarget(generateTarget);
|
||||
generateAction.setTarget(target);
|
||||
return actionRepository.save(generateAction);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Test DistributionSetCreatedEvent and DistributionSetUpdateEvent")
|
||||
public class DistributionSetEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the distribution set entity reloading by remote created event works")
|
||||
public void testDistributionSetCreatedEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetCreatedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the distribution set entity reloading by remote updated event works")
|
||||
public void testDistributionSetUpdateEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetUpdateEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DistributionSet createEntity() {
|
||||
return distributionSetManagement.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2",
|
||||
"incomplete", distributionSetManagement.findDistributionSetTypeByKey("os"), null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Test DistributionSetTagCreatedEvent and DistributionSetTagUpdateEvent")
|
||||
public class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest<DistributionSetTag> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the distribution set tag entity reloading by remote created event works")
|
||||
public void testDistributionSetTagCreatedEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetTagCreatedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the distribution set tag entity reloading by remote updated event works")
|
||||
public void testDistributionSetTagUpdateEvent() {
|
||||
assertAndCreateRemoteEvent(DistributionSetTagUpdateEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DistributionSetTag createEntity() {
|
||||
return tagManagement.createDistributionSetTag(entityFactory.generateDistributionSetTag("tag1"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Test RolloutUpdatedEvent")
|
||||
public class RolloutEventTest extends AbstractRemoteEntityEventTest<Rollout> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the rollout entity reloading by remote updated event works")
|
||||
public void testRolloutUpdatedEvent() {
|
||||
assertAndCreateRemoteEvent(RolloutUpdatedEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Rollout createEntity() {
|
||||
targetManagement.createTarget(entityFactory.generateTarget("12345"));
|
||||
final DistributionSet ds = distributionSetManagement
|
||||
.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2", "incomplete",
|
||||
distributionSetManagement.findDistributionSetTypeByKey("os"), null));
|
||||
|
||||
final Rollout rollout = entityFactory.generateRollout();
|
||||
rollout.setName("exampleRollout");
|
||||
rollout.setTargetFilterQuery("controllerId==*");
|
||||
rollout.setDistributionSet(ds);
|
||||
|
||||
final JpaRollout entity = (JpaRollout) rolloutManagement.createRollout(rollout, 10,
|
||||
new RolloutGroupConditionBuilder().successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10")
|
||||
.build());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Test RolloutGroupCreatedEvent and RolloutGroupUpdatedEvent")
|
||||
public class RolloutGroupEventTest extends AbstractRemoteEntityEventTest<RolloutGroup> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the rollout group entity reloading by remote created event works")
|
||||
public void testRolloutGroupCreatedEvent() {
|
||||
final RolloutGroupCreatedEvent createdEvent = (RolloutGroupCreatedEvent) assertAndCreateRemoteEvent(
|
||||
RolloutGroupCreatedEvent.class);
|
||||
assertThat(createdEvent.getRolloutId()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the rollout group entity reloading by remote updated event works")
|
||||
public void testRolloutGroupUpdatedEvent() {
|
||||
assertAndCreateRemoteEvent(RolloutGroupUpdatedEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RolloutGroup createEntity() {
|
||||
targetManagement.createTarget(entityFactory.generateTarget(UUID.randomUUID().toString()));
|
||||
final DistributionSet ds = distributionSetManagement
|
||||
.createDistributionSet(entityFactory.generateDistributionSet(UUID.randomUUID().toString(), "2",
|
||||
"incomplete", distributionSetManagement.findDistributionSetTypeByKey("os"), null));
|
||||
|
||||
final Rollout rollout = entityFactory.generateRollout();
|
||||
rollout.setName(UUID.randomUUID().toString());
|
||||
rollout.setTargetFilterQuery("controllerId==*");
|
||||
rollout.setDistributionSet(ds);
|
||||
|
||||
final JpaRollout entity = (JpaRollout) rolloutManagement.createRollout(rollout, 10,
|
||||
new RolloutGroupConditionBuilder().successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10")
|
||||
.build());
|
||||
|
||||
return rolloutManagement.findRolloutById(entity.getId()).getRolloutGroups().get(0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Test TargetCreatedEvent, TargetUpdatedEvent and CancelTargetAssignmentEvent")
|
||||
public class TargetEventTest extends AbstractRemoteEntityEventTest<Target> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the target entity reloading by remote created event works")
|
||||
public void testTargetCreatedEvent() {
|
||||
assertAndCreateRemoteEvent(TargetCreatedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the target entity reloading by remote updated event works")
|
||||
public void testTargetUpdatedEvent() {
|
||||
assertAndCreateRemoteEvent(TargetUpdatedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that cancel target assignment event works")
|
||||
public void testCancelTargetAssignmentEvent() {
|
||||
final Target target = createEntity();
|
||||
final CancelTargetAssignmentEvent assignmentEvent = new CancelTargetAssignmentEvent(target, 1L, "node");
|
||||
final CancelTargetAssignmentEvent underTest = (CancelTargetAssignmentEvent) assertEntity(target,
|
||||
assignmentEvent);
|
||||
|
||||
assertThat(underTest.getActionId()).isNotNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Target createEntity() {
|
||||
return targetManagement.createTarget(entityFactory.generateTarget("12345"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the remote entity events.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Test TargetTagCreatedEvent and TargetTagUpdateEvent")
|
||||
public class TargetTagEventTest extends AbstractRemoteEntityEventTest<TargetTag> {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the target tag entity reloading by remote created event works")
|
||||
public void testTargetTagCreatedEvent() {
|
||||
assertAndCreateRemoteEvent(TargetTagCreatedEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the target tag entity reloading by remote updated event works")
|
||||
public void testTargetTagUpdateEventt() {
|
||||
assertAndCreateRemoteEvent(TargetTagUpdateEvent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TargetTag createEntity() {
|
||||
return tagManagement.createTargetTag(entityFactory.generateTargetTag("tag1"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,9 +22,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
@@ -41,20 +40,22 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.ActionWithStatusCount;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
@@ -69,8 +70,21 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Stories("Deployment Management")
|
||||
public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private EventHandlerStub eventHandlerStub;
|
||||
|
||||
private CancelEventHandlerStub cancelEventHandlerStub;
|
||||
|
||||
@Autowired
|
||||
private EventBus eventBus;
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@Before
|
||||
public void addHandler() {
|
||||
eventHandlerStub = new EventHandlerStub();
|
||||
applicationContext.addApplicationListener(eventHandlerStub);
|
||||
|
||||
cancelEventHandlerStub = new CancelEventHandlerStub();
|
||||
applicationContext.addApplicationListener(cancelEventHandlerStub);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.")
|
||||
@@ -86,6 +100,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(action.getTarget()).as("Target in action").isNotNull();
|
||||
assertThat(action.getTarget().getAssignedDistributionSet()).as("AssignedDistributionSet of target in action")
|
||||
.isNotNull();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -377,9 +392,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Simple deployment or distribution set to target assignment test.")
|
||||
public void assignDistributionSet2Targets() throws InterruptedException {
|
||||
|
||||
final EventHandlerMock eventHandlerMock = new EventHandlerMock(20);
|
||||
eventBus.register(eventHandlerMock);
|
||||
eventHandlerStub.setExpectedNumberOfEvents(20);
|
||||
|
||||
final String myCtrlIDPref = "myCtrlID";
|
||||
final Iterable<Target> savedNakedTargets = targetManagement
|
||||
@@ -425,7 +438,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
final List<TargetAssignDistributionSetEvent> events = eventHandlerMock.getEvents(10, TimeUnit.SECONDS);
|
||||
final List<TargetAssignDistributionSetEvent> events = eventHandlerStub.getEvents(10, TimeUnit.SECONDS);
|
||||
|
||||
assertTargetAssignDistributionSetEvents(savedDeployedTargets, ds, events);
|
||||
}
|
||||
@@ -433,8 +446,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Test that it is not possible to assign a distribution set that is not complete.")
|
||||
public void failDistributionSetAssigmentThatIsNotComplete() throws InterruptedException {
|
||||
final EventHandlerMock eventHandlerMock = new EventHandlerMock(0);
|
||||
eventBus.register(eventHandlerMock);
|
||||
eventHandlerStub.setExpectedNumberOfEvents(0);
|
||||
|
||||
final List<Target> targets = testdataFactory.createTargets(10);
|
||||
|
||||
@@ -454,21 +466,20 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
} catch (final IncompleteDistributionSetException ex) {
|
||||
}
|
||||
|
||||
// give some chance to receive events asynchronously
|
||||
Thread.sleep(1L);
|
||||
final List<TargetAssignDistributionSetEvent> events = eventHandlerStub.getEvents(5, TimeUnit.SECONDS);
|
||||
assertThat(events).as("events should be empty").isEmpty();
|
||||
|
||||
incomplete.addModule(os);
|
||||
final DistributionSet nowComplete = distributionSetManagement.updateDistributionSet(incomplete);
|
||||
|
||||
// give some chance to receive events asynchronously
|
||||
Thread.sleep(300);
|
||||
final List<TargetAssignDistributionSetEvent> events = eventHandlerMock.getEvents(1, TimeUnit.MILLISECONDS);
|
||||
assertThat(events).as("events should be empty").isEmpty();
|
||||
|
||||
final EventHandlerMock eventHandlerMockAfterCompletionOfDs = new EventHandlerMock(10);
|
||||
eventBus.register(eventHandlerMockAfterCompletionOfDs);
|
||||
eventHandlerStub.setExpectedNumberOfEvents(10);
|
||||
|
||||
assertThat(deploymentManagement.assignDistributionSet(nowComplete, targets).getAssigned())
|
||||
.as("assign ds doesn't work").isEqualTo(10);
|
||||
assertTargetAssignDistributionSetEvents(targets, nowComplete,
|
||||
eventHandlerMockAfterCompletionOfDs.getEvents(10, TimeUnit.SECONDS));
|
||||
|
||||
assertTargetAssignDistributionSetEvents(targets, nowComplete, eventHandlerStub.getEvents(15, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -485,15 +496,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// Each of the four targets get one assignment (4 * 1 = 4)
|
||||
final int expectedNumberOfEventsForAssignment = 4;
|
||||
final EventHandlerMock eventHandlerMock = new EventHandlerMock(expectedNumberOfEventsForAssignment);
|
||||
eventBus.register(eventHandlerMock);
|
||||
eventHandlerStub.setExpectedNumberOfEvents(expectedNumberOfEventsForAssignment);
|
||||
|
||||
// Each of the four targets get two more assignment the which are
|
||||
// cancelled (4 * 2 = 8)
|
||||
final int expectedNumberOfEventsForCancel = 8;
|
||||
final CancelEventHandlerMock cancelEventHandlerMock = new CancelEventHandlerMock(
|
||||
expectedNumberOfEventsForCancel);
|
||||
eventBus.register(cancelEventHandlerMock);
|
||||
cancelEventHandlerStub.setExpectedNumberOfEvents(expectedNumberOfEventsForCancel);
|
||||
|
||||
final DeploymentResult deploymentResult = prepareComplexRepo(undeployedTargetPrefix, noOfUndeployedTargets,
|
||||
deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS");
|
||||
@@ -535,10 +543,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.doesNotContain(Iterables.toArray(deployedTargetsFromDB, JpaTarget.class));
|
||||
|
||||
// For each of the 4 targets 1 distribution sets gets assigned
|
||||
eventHandlerMock.getEvents(10, TimeUnit.SECONDS);
|
||||
eventHandlerStub.getEvents(10, TimeUnit.SECONDS);
|
||||
|
||||
// For each of the 4 targets 2 distribution sets gets cancelled
|
||||
cancelEventHandlerMock.getEvents(10, TimeUnit.SECONDS);
|
||||
cancelEventHandlerStub.getEvents(10, TimeUnit.SECONDS);
|
||||
|
||||
}
|
||||
|
||||
@@ -825,7 +833,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
|
||||
final List<Target> targs = new ArrayList<Target>();
|
||||
final List<Target> targs = new ArrayList<>();
|
||||
targs.add(targ);
|
||||
final Iterable<Target> savedTargs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedEntity();
|
||||
targ = savedTargs.iterator().next();
|
||||
@@ -934,17 +942,20 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void assertTargetAssignDistributionSetEvents(final List<Target> targets, final DistributionSet ds,
|
||||
final List<TargetAssignDistributionSetEvent> events) {
|
||||
assertThat(events).isNotEmpty();
|
||||
for (final Target myt : targets) {
|
||||
boolean found = false;
|
||||
for (final TargetAssignDistributionSetEvent event : events) {
|
||||
if (event.getTarget().getControllerId().equals(myt.getControllerId())) {
|
||||
if (event.getControllerId().equals(myt.getControllerId())) {
|
||||
found = true;
|
||||
final List<Action> activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(myt);
|
||||
assertThat(activeActionsByTarget).as("size of active actions for target is wrong").isNotEmpty();
|
||||
assertThat(event.getActionId()).as("Action id in database and event do not match")
|
||||
.isEqualTo(activeActionsByTarget.get(0).getId());
|
||||
assertThat(event.getSoftwareModules()).as("softwaremodule size is not correct")
|
||||
.containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()]));
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetById(event.getDistributionSetId())
|
||||
.getModules()).as("softwaremodule size is not correct")
|
||||
.containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()]));
|
||||
}
|
||||
}
|
||||
assertThat(found).as("No event found for controller " + myt.getControllerId()).isTrue();
|
||||
@@ -952,19 +963,17 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
private class DeploymentResult
|
||||
private class DeploymentResult {
|
||||
final List<Long> deployedTargetIDs = new ArrayList<>();
|
||||
final List<Long> undeployedTargetIDs = new ArrayList<>();
|
||||
final List<Long> distributionSetIDs = new ArrayList<>();
|
||||
|
||||
{
|
||||
final List<Long> deployedTargetIDs = new ArrayList<Long>();
|
||||
final List<Long> undeployedTargetIDs = new ArrayList<Long>();
|
||||
final List<Long> distributionSetIDs = new ArrayList<Long>();
|
||||
|
||||
private final List<Target> undeployedTargets = new ArrayList<Target>();
|
||||
private final List<Target> deployedTargets = new ArrayList<Target>();
|
||||
private final List<DistributionSet> distributionSets = new ArrayList<DistributionSet>();
|
||||
private final List<Target> undeployedTargets = new ArrayList<>();
|
||||
private final List<Target> deployedTargets = new ArrayList<>();
|
||||
private final List<DistributionSet> distributionSets = new ArrayList<>();
|
||||
|
||||
public DeploymentResult(final Iterable<Target> deployedTs, final Iterable<Target> undeployedTs,
|
||||
final Iterable<DistributionSet> dss, final String deployedTargetPrefix,
|
||||
@@ -982,101 +991,97 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the distributionSetIDs
|
||||
*/
|
||||
public List<Long> getDistributionSetIDs() {
|
||||
return distributionSetIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public List<Long> getDeployedTargetIDs() {
|
||||
return deployedTargetIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public List<Target> getUndeployedTargets() {
|
||||
return undeployedTargets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public List<DistributionSet> getDistributionSets() {
|
||||
return distributionSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public List<Target> getDeployedTargets() {
|
||||
return deployedTargets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the undeployedTargetIDs
|
||||
*/
|
||||
public List<Long> getUndeployedTargetIDs() {
|
||||
return undeployedTargetIDs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class EventHandlerMock {
|
||||
protected static class EventHandlerStub implements ApplicationListener<TargetAssignDistributionSetEvent> {
|
||||
private final List<TargetAssignDistributionSetEvent> events = Collections.synchronizedList(new LinkedList<>());
|
||||
private final CountDownLatch latch;
|
||||
private final int expectedNumberOfEvents;
|
||||
private CountDownLatch latch;
|
||||
private int expectedNumberOfEvents;
|
||||
|
||||
private EventHandlerMock(final int expectedNumberOfEvents) {
|
||||
/**
|
||||
* @param expectedNumberOfEvents
|
||||
* the expectedNumberOfEvents to set
|
||||
*/
|
||||
public void setExpectedNumberOfEvents(final int expectedNumberOfEvents) {
|
||||
events.clear();
|
||||
this.expectedNumberOfEvents = expectedNumberOfEvents;
|
||||
this.latch = new CountDownLatch(expectedNumberOfEvents);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleEvent(final TargetAssignDistributionSetEvent event) {
|
||||
events.add(event);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
public List<TargetAssignDistributionSetEvent> getEvents(final long timeout, final TimeUnit unit)
|
||||
throws InterruptedException {
|
||||
latch.await(timeout, unit);
|
||||
final List<TargetAssignDistributionSetEvent> handledEvents = new LinkedList<>(events);
|
||||
final List<TargetAssignDistributionSetEvent> handledEvents = Collections
|
||||
.unmodifiableList(new LinkedList<>(events));
|
||||
assertThat(handledEvents).as("Did not receive the expected amount of events (" + expectedNumberOfEvents
|
||||
+ ") within timeout. Received events are " + handledEvents).hasSize(expectedNumberOfEvents);
|
||||
|
||||
return handledEvents;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(final TargetAssignDistributionSetEvent event) {
|
||||
if (latch == null) {
|
||||
return;
|
||||
}
|
||||
events.add(event);
|
||||
latch.countDown();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static class CancelEventHandlerMock {
|
||||
private static class CancelEventHandlerStub implements ApplicationListener<CancelTargetAssignmentEvent> {
|
||||
private final List<CancelTargetAssignmentEvent> events = Collections.synchronizedList(new LinkedList<>());
|
||||
private final CountDownLatch latch;
|
||||
private final int expectedNumberOfEvents;
|
||||
private CountDownLatch latch;
|
||||
private int expectedNumberOfEvents;
|
||||
|
||||
private CancelEventHandlerMock(final int expectedNumberOfEvents) {
|
||||
public void setExpectedNumberOfEvents(final int expectedNumberOfEvents) {
|
||||
events.clear();
|
||||
this.expectedNumberOfEvents = expectedNumberOfEvents;
|
||||
this.latch = new CountDownLatch(expectedNumberOfEvents);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleEvent(final CancelTargetAssignmentEvent event) {
|
||||
events.add(event);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
public List<CancelTargetAssignmentEvent> getEvents(final long timeout, final TimeUnit unit)
|
||||
throws InterruptedException {
|
||||
latch.await(timeout, unit);
|
||||
final List<CancelTargetAssignmentEvent> handledEvents = new LinkedList<CancelTargetAssignmentEvent>(events);
|
||||
final List<CancelTargetAssignmentEvent> handledEvents = new LinkedList<>(events);
|
||||
assertThat(handledEvents).as("Did not receive the expected amount of events (" + expectedNumberOfEvents
|
||||
+ ") within timeout. Received events are " + handledEvents).hasSize(expectedNumberOfEvents);
|
||||
return handledEvents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(final CancelTargetAssignmentEvent event) {
|
||||
if (latch == null) {
|
||||
return;
|
||||
}
|
||||
events.add(event);
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
@@ -35,6 +34,7 @@ import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.ReportManagement;
|
||||
import org.eclipse.hawkbit.repository.ReportManagement.DateTypes;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
@@ -30,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
@@ -269,7 +269,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a deleted tag is removed from the repository as defined.")
|
||||
public void deleteTargetTas() {
|
||||
public void deleteTargetTags() {
|
||||
|
||||
// create test data
|
||||
final Iterable<JpaTargetTag> tags = createTargetsWithTags();
|
||||
|
||||
@@ -29,7 +29,6 @@ import javax.persistence.Query;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
@@ -39,6 +38,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetIdName;
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -222,7 +223,7 @@ public class TenantConfigurationManagementTest extends AbstractJpaIntegrationTes
|
||||
public void requestConfigValueWithWrongType() {
|
||||
try {
|
||||
tenantConfigurationManagement.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL,
|
||||
Object.class);
|
||||
Serializable.class);
|
||||
Assert.fail("");
|
||||
} catch (final TenantConfigurationValidatorException e) {
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.cache;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Unit Tests - Repository")
|
||||
@Stories("CacheKeys")
|
||||
public class CacheKeysTest {
|
||||
|
||||
@Test
|
||||
public void entitySpecificCacheKeyPattern() {
|
||||
final String knownEntityId = "123";
|
||||
final String knownCacheKey = "someField";
|
||||
final String entitySpecificCacheKey = CacheKeys.entitySpecificCacheKey(knownEntityId, knownCacheKey);
|
||||
assertThat(entitySpecificCacheKey).isEqualTo(knownEntityId + "." + knownCacheKey);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.cache;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Unit Tests - Repository")
|
||||
@Stories("CacheWriteNotify")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CacheWriteNotifyTest {
|
||||
|
||||
@Mock
|
||||
private EventBus eventBusMock;
|
||||
|
||||
@Mock
|
||||
private CacheManager cacheManagerMock;
|
||||
|
||||
@Mock
|
||||
private Cache cacheMock;
|
||||
|
||||
@Mock
|
||||
private TenantAware tenantAwareMock;
|
||||
|
||||
private CacheWriteNotify underTest;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
underTest = new CacheWriteNotify();
|
||||
underTest.setEventBus(eventBusMock);
|
||||
underTest.setCacheManager(cacheManagerMock);
|
||||
underTest.setTenantAware(tenantAwareMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadgProgressIsCachedAndEventSent() {
|
||||
final long knownStatusId = 1;
|
||||
|
||||
when(cacheManagerMock.getCache(ActionStatus.class.getName())).thenReturn(cacheMock);
|
||||
when(tenantAwareMock.getCurrentTenant()).thenReturn("default");
|
||||
|
||||
underTest.downloadProgress(knownStatusId, 500L, 100L, 100L);
|
||||
|
||||
verify(cacheManagerMock).getCache(eq(ActionStatus.class.getName()));
|
||||
verify(cacheMock).put(knownStatusId + "." + CacheKeys.DOWNLOAD_PROGRESS_PERCENT, 20);
|
||||
verify(eventBusMock).post(any(DownloadProgressEvent.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,33 +6,31 @@
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.eventbus;
|
||||
package org.eclipse.hawkbit.repository.jpa.event;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.Event;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.TenantAwareEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.event.RepositoryEntityEventTest.RepositoryTestConfiguration;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.fest.assertions.api.Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
@@ -40,17 +38,15 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Entity Events")
|
||||
@SpringApplicationConfiguration(classes = RepositoryTestConfiguration.class)
|
||||
public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private EventBus eventBus;
|
||||
|
||||
private final MyEventListener eventListener = new MyEventListener();
|
||||
private MyEventListener eventListener;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
eventListener.queue.clear();
|
||||
eventBus.register(eventListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,19 +73,6 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetUpdatedEvent.getEntity().getId()).isEqualTo(createdTarget.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the target info update event is published when a target info has been updated")
|
||||
public void targetInfoUpdateEventIsPublished() throws InterruptedException {
|
||||
final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345"));
|
||||
controllerManagament.updateTargetStatus(createdTarget.getTargetInfo(), TargetUpdateStatus.PENDING,
|
||||
System.currentTimeMillis(), URI.create("http://127.0.0.1"));
|
||||
|
||||
final TargetInfoUpdateEvent targetInfoUpdatedEvent = eventListener.waitForEvent(TargetInfoUpdateEvent.class, 1,
|
||||
TimeUnit.SECONDS);
|
||||
assertThat(targetInfoUpdatedEvent).isNotNull();
|
||||
assertThat(targetInfoUpdatedEvent.getEntity().getTarget().getId()).isEqualTo(createdTarget.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the target deleted event is published when a target has been deleted")
|
||||
public void targetDeletedEventIsPublished() throws InterruptedException {
|
||||
@@ -100,7 +83,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
final TargetDeletedEvent targetDeletedEvent = eventListener.waitForEvent(TargetDeletedEvent.class, 1,
|
||||
TimeUnit.SECONDS);
|
||||
assertThat(targetDeletedEvent).isNotNull();
|
||||
assertThat(targetDeletedEvent.getTargetId()).isEqualTo(createdTarget.getId());
|
||||
assertThat(targetDeletedEvent.getEntityId()).isEqualTo(createdTarget.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,8 +95,8 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet createDistributionSet = distributionSetManagement
|
||||
.createDistributionSet(generateDistributionSet);
|
||||
|
||||
final DistributionCreatedEvent dsCreatedEvent = eventListener.waitForEvent(DistributionCreatedEvent.class, 1,
|
||||
TimeUnit.SECONDS);
|
||||
final DistributionSetCreatedEvent dsCreatedEvent = eventListener.waitForEvent(DistributionSetCreatedEvent.class,
|
||||
1, TimeUnit.SECONDS);
|
||||
assertThat(dsCreatedEvent).isNotNull();
|
||||
assertThat(dsCreatedEvent.getEntity().getId()).isEqualTo(createDistributionSet.getId());
|
||||
}
|
||||
@@ -130,24 +113,33 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(createDistributionSet);
|
||||
|
||||
final DistributionDeletedEvent dsDeletedEvent = eventListener.waitForEvent(DistributionDeletedEvent.class, 1,
|
||||
TimeUnit.SECONDS);
|
||||
final DistributionSetDeletedEvent dsDeletedEvent = eventListener.waitForEvent(DistributionSetDeletedEvent.class,
|
||||
1, TimeUnit.SECONDS);
|
||||
assertThat(dsDeletedEvent).isNotNull();
|
||||
assertThat(dsDeletedEvent.getDistributionSetId()).isEqualTo(createDistributionSet.getId());
|
||||
assertThat(dsDeletedEvent.getEntityId()).isEqualTo(createDistributionSet.getId());
|
||||
}
|
||||
|
||||
private class MyEventListener {
|
||||
public static class RepositoryTestConfiguration {
|
||||
|
||||
private final BlockingQueue<Event> queue = new LinkedBlockingQueue<>();
|
||||
@Bean
|
||||
public MyEventListener myEventListenerBean() {
|
||||
return new MyEventListener();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(final Event event) {
|
||||
}
|
||||
|
||||
private static class MyEventListener {
|
||||
|
||||
private final BlockingQueue<TenantAwareEvent> queue = new LinkedBlockingQueue<>();
|
||||
|
||||
@EventListener(classes = TenantAwareEvent.class)
|
||||
public void onEvent(final TenantAwareEvent event) {
|
||||
queue.offer(event);
|
||||
}
|
||||
|
||||
public <T> T waitForEvent(final Class<T> eventType, final long timeout, final TimeUnit timeUnit)
|
||||
throws InterruptedException {
|
||||
Event event = null;
|
||||
TenantAwareEvent event = null;
|
||||
while ((event = queue.poll(timeout, timeUnit)) != null) {
|
||||
if (event.getClass().isAssignableFrom(eventType)) {
|
||||
return (T) event;
|
||||
@@ -1,129 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.eventbus;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.cache.CacheField;
|
||||
import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.support.SimpleValueWrapper;
|
||||
import org.springframework.hateoas.Identifiable;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Unit Tests - Repository")
|
||||
@Stories("EventBus")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CacheFieldEntityListenerTest {
|
||||
|
||||
private static final String TEST_CACHE_FIELD = "testCacheField";
|
||||
|
||||
@Mock
|
||||
private CacheManager cacheManagerMock;
|
||||
|
||||
@Mock
|
||||
private Cache cacheMock;
|
||||
|
||||
private CacheFieldEntityListener underTest;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
// mock
|
||||
when(cacheManagerMock.getCache(anyString())).thenReturn(cacheMock);
|
||||
|
||||
underTest = new CacheFieldEntityListener();
|
||||
CacheManagerHolder.getInstance().setCacheManager(cacheManagerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postLoadSetsCacheFields() {
|
||||
final String entityId = "123";
|
||||
final String normalFieldValue = "bumlux";
|
||||
final TestEntity testObject = new TestEntity(entityId, normalFieldValue);
|
||||
final int expectedTestValue = -1;
|
||||
|
||||
when(cacheMock.get(CacheKeys.entitySpecificCacheKey(entityId, TEST_CACHE_FIELD)))
|
||||
.thenReturn(new SimpleValueWrapper(expectedTestValue));
|
||||
|
||||
// pre verify everything is ok
|
||||
assertThat(testObject.getCacheField()).isNotEqualTo(expectedTestValue);
|
||||
assertThat(testObject.getNormalField()).isEqualTo(normalFieldValue);
|
||||
|
||||
// test
|
||||
underTest.postLoad(testObject);
|
||||
|
||||
assertThat(testObject.getNormalField()).isEqualTo(normalFieldValue);
|
||||
// now cache value should be like the value in the mock of the cache
|
||||
assertThat(testObject.getCacheField()).isEqualTo(expectedTestValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRemoveEvictsCacheField() {
|
||||
final String entityId = "123";
|
||||
final String normalFieldValue = "bumlux";
|
||||
final TestEntity testObject = new TestEntity(entityId, normalFieldValue);
|
||||
// test
|
||||
underTest.postDelete(testObject);
|
||||
|
||||
verify(cacheMock).evict(eq(CacheKeys.entitySpecificCacheKey(entityId, TEST_CACHE_FIELD)));
|
||||
}
|
||||
|
||||
private final class TestEntity implements Identifiable<String> {
|
||||
|
||||
private final String id;
|
||||
|
||||
private final String normalField;
|
||||
|
||||
@CacheField(key = TEST_CACHE_FIELD)
|
||||
private int cacheField;
|
||||
|
||||
private TestEntity(final String id, final String normalFieldValue) {
|
||||
this.id = id;
|
||||
this.normalField = normalFieldValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.hateoas.Identifiable#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the normalField
|
||||
*/
|
||||
String getNormalField() {
|
||||
return normalField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cacheField
|
||||
*/
|
||||
int getCacheField() {
|
||||
return cacheField;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,13 @@ import org.eclipse.hawkbit.repository.FieldNameProvider;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -18,8 +18,9 @@ import java.time.Instant;
|
||||
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
|
||||
logging.level.=INFO
|
||||
logging.level.org.eclipse.persistence=ERROR
|
||||
|
||||
spring.data.mongodb.uri=mongodb://localhost/spArtifactRepository${random.value}
|
||||
spring.data.mongodb.port=28017
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
which accompanies this distribution, and is available at
|
||||
http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
-->
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml" />
|
||||
|
||||
<!-- <logger name="org.eclipse.persistence" level="DEBUG" /> -->
|
||||
|
||||
<Root level="INFO">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</Root>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user