Commit 9ee0d87687eb539e366a49eb58505236c7295ea7

Authored by Sergey Matvienko
1 parent ac2844b5

tests: Coap client destroy on processAfterTest at AbstractCoapIntegrationTest

@@ -52,6 +52,16 @@ import static org.junit.Assert.assertNotNull; @@ -52,6 +52,16 @@ import static org.junit.Assert.assertNotNull;
52 @Slf4j 52 @Slf4j
53 public abstract class AbstractCoapIntegrationTest extends AbstractTransportIntegrationTest { 53 public abstract class AbstractCoapIntegrationTest extends AbstractTransportIntegrationTest {
54 54
  55 + protected CoapClient client;
  56 +
  57 + @Override
  58 + protected void processAfterTest() throws Exception {
  59 + if (client != null) {
  60 + client.shutdown();
  61 + }
  62 + super.processAfterTest();
  63 + }
  64 +
55 protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception { 65 protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception {
56 this.processBeforeTest(deviceName, coapDeviceType, payloadType, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED); 66 this.processBeforeTest(deviceName, coapDeviceType, payloadType, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED);
57 } 67 }
@@ -75,7 +75,7 @@ public abstract class AbstractCoapAttributesRequestIntegrationTest extends Abstr @@ -75,7 +75,7 @@ public abstract class AbstractCoapAttributesRequestIntegrationTest extends Abstr
75 75
76 String keys = "attribute1,attribute2,attribute3,attribute4,attribute5"; 76 String keys = "attribute1,attribute2,attribute3,attribute4,attribute5";
77 String featureTokenUrl = getFeatureTokenUrl(accessToken, FeatureType.ATTRIBUTES) + "?clientKeys=" + keys + "&sharedKeys=" + keys; 77 String featureTokenUrl = getFeatureTokenUrl(accessToken, FeatureType.ATTRIBUTES) + "?clientKeys=" + keys + "&sharedKeys=" + keys;
78 - CoapClient client = getCoapClient(featureTokenUrl); 78 + client = getCoapClient(featureTokenUrl);
79 79
80 CoapResponse getAttributesResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).get(); 80 CoapResponse getAttributesResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).get();
81 validateResponse(getAttributesResponse); 81 validateResponse(getAttributesResponse);
@@ -83,7 +83,7 @@ public abstract class AbstractCoapAttributesRequestIntegrationTest extends Abstr @@ -83,7 +83,7 @@ public abstract class AbstractCoapAttributesRequestIntegrationTest extends Abstr
83 83
84 protected void postAttributes() throws Exception { 84 protected void postAttributes() throws Exception {
85 doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD, String.class, status().isOk()); 85 doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD, String.class, status().isOk());
86 - CoapClient client = getCoapClient(FeatureType.ATTRIBUTES); 86 + client = getCoapClient(FeatureType.ATTRIBUTES);
87 CoapResponse coapResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).post(POST_ATTRIBUTES_PAYLOAD.getBytes(), MediaTypeRegistry.APPLICATION_JSON); 87 CoapResponse coapResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).post(POST_ATTRIBUTES_PAYLOAD.getBytes(), MediaTypeRegistry.APPLICATION_JSON);
88 assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode()); 88 assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode());
89 } 89 }
@@ -21,7 +21,6 @@ import com.google.protobuf.DynamicMessage; @@ -21,7 +21,6 @@ import com.google.protobuf.DynamicMessage;
21 import com.google.protobuf.InvalidProtocolBufferException; 21 import com.google.protobuf.InvalidProtocolBufferException;
22 import com.squareup.wire.schema.internal.parser.ProtoFileElement; 22 import com.squareup.wire.schema.internal.parser.ProtoFileElement;
23 import lombok.extern.slf4j.Slf4j; 23 import lombok.extern.slf4j.Slf4j;
24 -import org.eclipse.californium.core.CoapClient;  
25 import org.eclipse.californium.core.CoapResponse; 24 import org.eclipse.californium.core.CoapResponse;
26 import org.eclipse.californium.core.coap.CoAP; 25 import org.eclipse.californium.core.coap.CoAP;
27 import org.eclipse.californium.core.coap.MediaTypeRegistry; 26 import org.eclipse.californium.core.coap.MediaTypeRegistry;
@@ -124,7 +123,7 @@ public abstract class AbstractCoapAttributesRequestProtoIntegrationTest extends @@ -124,7 +123,7 @@ public abstract class AbstractCoapAttributesRequestProtoIntegrationTest extends
124 .setField(postAttributesMsgDescriptor.findFieldByName("attribute5"), jsonObject) 123 .setField(postAttributesMsgDescriptor.findFieldByName("attribute5"), jsonObject)
125 .build(); 124 .build();
126 byte[] payload = postAttributesMsg.toByteArray(); 125 byte[] payload = postAttributesMsg.toByteArray();
127 - CoapClient client = getCoapClient(FeatureType.ATTRIBUTES); 126 + client = getCoapClient(FeatureType.ATTRIBUTES);
128 CoapResponse coapResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).post(payload, MediaTypeRegistry.APPLICATION_JSON); 127 CoapResponse coapResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).post(payload, MediaTypeRegistry.APPLICATION_JSON);
129 assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode()); 128 assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode());
130 } 129 }
@@ -71,7 +71,7 @@ public abstract class AbstractCoapAttributesUpdatesIntegrationTest extends Abstr @@ -71,7 +71,7 @@ public abstract class AbstractCoapAttributesUpdatesIntegrationTest extends Abstr
71 if (!emptyCurrentStateNotification) { 71 if (!emptyCurrentStateNotification) {
72 doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD_ON_CURRENT_STATE_NOTIFICATION, String.class, status().isOk()); 72 doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD_ON_CURRENT_STATE_NOTIFICATION, String.class, status().isOk());
73 } 73 }
74 - CoapClient client = getCoapClient(FeatureType.ATTRIBUTES); 74 + client = getCoapClient(FeatureType.ATTRIBUTES);
75 75
76 CountDownLatch latch = new CountDownLatch(1); 76 CountDownLatch latch = new CountDownLatch(1);
77 TestCoapCallback callback = new TestCoapCallback(latch); 77 TestCoapCallback callback = new TestCoapCallback(latch);
@@ -90,7 +90,7 @@ public abstract class AbstractCoapClaimDeviceTest extends AbstractCoapIntegratio @@ -90,7 +90,7 @@ public abstract class AbstractCoapClaimDeviceTest extends AbstractCoapIntegratio
90 90
91 protected void processTestClaimingDevice(boolean emptyPayload) throws Exception { 91 protected void processTestClaimingDevice(boolean emptyPayload) throws Exception {
92 log.warn("[testClaimingDevice] Device: {}, Transport type: {}", savedDevice.getName(), savedDevice.getType()); 92 log.warn("[testClaimingDevice] Device: {}, Transport type: {}", savedDevice.getName(), savedDevice.getType());
93 - CoapClient client = getCoapClient(FeatureType.CLAIM); 93 + client = getCoapClient(FeatureType.CLAIM);
94 byte[] payloadBytes; 94 byte[] payloadBytes;
95 byte[] failurePayloadBytes; 95 byte[] failurePayloadBytes;
96 if (emptyPayload) { 96 if (emptyPayload) {
@@ -49,7 +49,7 @@ public abstract class AbstractCoapClaimProtoDeviceTest extends AbstractCoapClaim @@ -49,7 +49,7 @@ public abstract class AbstractCoapClaimProtoDeviceTest extends AbstractCoapClaim
49 49
50 @Override 50 @Override
51 protected void processTestClaimingDevice(boolean emptyPayload) throws Exception { 51 protected void processTestClaimingDevice(boolean emptyPayload) throws Exception {
52 - CoapClient client = getCoapClient(FeatureType.CLAIM); 52 + client = getCoapClient(FeatureType.CLAIM);
53 byte[] payloadBytes; 53 byte[] payloadBytes;
54 if (emptyPayload) { 54 if (emptyPayload) {
55 TransportApiProtos.ClaimDevice claimDevice = getClaimDevice(0, emptyPayload); 55 TransportApiProtos.ClaimDevice claimDevice = getClaimDevice(0, emptyPayload);
@@ -180,7 +180,7 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn @@ -180,7 +180,7 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn
180 180
181 private CoapResponse createCoapClientAndPublish(String deviceCredentials) throws Exception { 181 private CoapResponse createCoapClientAndPublish(String deviceCredentials) throws Exception {
182 String provisionRequestMsg = createTestProvisionMessage(deviceCredentials); 182 String provisionRequestMsg = createTestProvisionMessage(deviceCredentials);
183 - CoapClient client = getCoapClient(FeatureType.PROVISION); 183 + client = getCoapClient(FeatureType.PROVISION);
184 return postProvision(client, provisionRequestMsg.getBytes()); 184 return postProvision(client, provisionRequestMsg.getBytes());
185 } 185 }
186 186
@@ -176,7 +176,7 @@ public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapI @@ -176,7 +176,7 @@ public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapI
176 } 176 }
177 177
178 private CoapResponse createCoapClientAndPublish(byte[] provisionRequestMsg) throws Exception { 178 private CoapResponse createCoapClientAndPublish(byte[] provisionRequestMsg) throws Exception {
179 - CoapClient client = getCoapClient(FeatureType.PROVISION); 179 + client = getCoapClient(FeatureType.PROVISION);
180 return postProvision(client, provisionRequestMsg); 180 return postProvision(client, provisionRequestMsg);
181 } 181 }
182 182
@@ -54,7 +54,7 @@ public abstract class AbstractCoapServerSideRpcIntegrationTest extends AbstractC @@ -54,7 +54,7 @@ public abstract class AbstractCoapServerSideRpcIntegrationTest extends AbstractC
54 } 54 }
55 55
56 protected void processOneWayRpcTest() throws Exception { 56 protected void processOneWayRpcTest() throws Exception {
57 - CoapClient client = getCoapClient(FeatureType.RPC); 57 + client = getCoapClient(FeatureType.RPC);
58 client.useCONs(); 58 client.useCONs();
59 59
60 CountDownLatch latch = new CountDownLatch(1); 60 CountDownLatch latch = new CountDownLatch(1);
@@ -82,7 +82,7 @@ public abstract class AbstractCoapServerSideRpcIntegrationTest extends AbstractC @@ -82,7 +82,7 @@ public abstract class AbstractCoapServerSideRpcIntegrationTest extends AbstractC
82 } 82 }
83 83
84 protected void processTwoWayRpcTest(String expectedResponseResult) throws Exception { 84 protected void processTwoWayRpcTest(String expectedResponseResult) throws Exception {
85 - CoapClient client = getCoapClient(FeatureType.RPC); 85 + client = getCoapClient(FeatureType.RPC);
86 client.useCONs(); 86 client.useCONs();
87 87
88 CountDownLatch latch = new CountDownLatch(1); 88 CountDownLatch latch = new CountDownLatch(1);
@@ -69,7 +69,7 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap @@ -69,7 +69,7 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap
69 } 69 }
70 70
71 protected void processAttributesTest(List<String> expectedKeys, byte[] payload, boolean presenceFieldsTest) throws Exception { 71 protected void processAttributesTest(List<String> expectedKeys, byte[] payload, boolean presenceFieldsTest) throws Exception {
72 - CoapClient client = getCoapClient(FeatureType.ATTRIBUTES); 72 + client = getCoapClient(FeatureType.ATTRIBUTES);
73 73
74 postAttributes(client, payload); 74 postAttributes(client, payload);
75 75
@@ -71,8 +71,8 @@ public abstract class AbstractCoapTimeseriesIntegrationTest extends AbstractCoap @@ -71,8 +71,8 @@ public abstract class AbstractCoapTimeseriesIntegrationTest extends AbstractCoap
71 } 71 }
72 72
73 protected void processTestPostTelemetry(byte[] payloadBytes, List<String> expectedKeys, boolean withTs, boolean presenceFieldsTest) throws Exception { 73 protected void processTestPostTelemetry(byte[] payloadBytes, List<String> expectedKeys, boolean withTs, boolean presenceFieldsTest) throws Exception {
74 - CoapClient coapClient = getCoapClient(FeatureType.TELEMETRY);  
75 - postTelemetry(coapClient, payloadBytes); 74 + client = getCoapClient(FeatureType.TELEMETRY);
  75 + postTelemetry(client, payloadBytes);
76 76
77 String deviceId = savedDevice.getId().getId().toString(); 77 String deviceId = savedDevice.getId().getId().toString();
78 78