Skip to content

Commit d031474

Browse files
authored
Merge pull request #337 from iExecBlockchainComputing/feature/dirty-5.0.1-rc
Decode 404 response from SMS & fix subscription NPE
2 parents d0abc7c + b2e0439 commit d031474

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version=5.1.0-SNAPSHOT
2-
iexecCommonVersion=5.0.0
2+
iexecCommonVersion=5.1.0-SNAPSHOT
33
nexusUser=fake
44
nexusPassword=fake

src/main/java/com/iexec/worker/feign/client/SmsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import feign.FeignException;
3030

31-
@FeignClient(name = "SmsClient", url = "#{publicConfigurationService.smsURL}")
31+
@FeignClient(name = "SmsClient", url = "#{publicConfigurationService.smsURL}", decode404 = true)
3232
public interface SmsClient {
3333

3434
@PostMapping("/untee/secrets")

src/main/java/com/iexec/worker/pubsub/StompClient.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Arrays;
2020
import java.util.List;
21+
import java.util.Optional;
2122
import java.util.concurrent.ArrayBlockingQueue;
2223
import java.util.concurrent.BlockingQueue;
2324
import java.util.concurrent.TimeUnit;
@@ -90,8 +91,12 @@ public StompClient(ApplicationEventPublisher applicationEventPublisher,
9091
* @param messageHandler an implementation of
9192
* @return
9293
*/
93-
Subscription subscribeToTopic(String topic, StompFrameHandler messageHandler) {
94-
return this.session.subscribe(topic, messageHandler);
94+
Optional<Subscription> subscribeToTopic(String topic, StompFrameHandler messageHandler) {
95+
// Should not let other threads subscribe
96+
// when the session is not ready yet.
97+
return this.session != null
98+
? Optional.of(this.session.subscribe(topic, messageHandler))
99+
: Optional.empty();
95100
}
96101

97102
@PostConstruct

src/main/java/com/iexec/worker/pubsub/SubscriptionService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@ public SubscriptionService(WorkerConfigurationService workerConfigurationService
5757
*
5858
* @param chainTaskId id of the task to which to subscribe
5959
*/
60-
public synchronized void subscribeToTopic(String chainTaskId) {
60+
public void subscribeToTopic(String chainTaskId) {
6161
String topic = getTaskTopicName(chainTaskId);
6262
if (this.chainTaskIdToSubscription.containsKey(chainTaskId)) {
6363
log.info("Already subscribed to topic [chainTaskId:{}, topic:{}]",
6464
chainTaskId, topic);
6565
return;
6666
}
6767
MessageHandler messageHandler = new MessageHandler(chainTaskId, this.workerWalletAddress);
68-
Subscription subscription = stompClient.subscribeToTopic(topic, messageHandler);
69-
this.chainTaskIdToSubscription.put(chainTaskId, subscription);
70-
log.info("Subscribed to topic [chainTaskId:{}, topic:{}]", chainTaskId, topic);
68+
stompClient.subscribeToTopic(topic, messageHandler).ifPresent(subscription -> {
69+
this.chainTaskIdToSubscription.put(chainTaskId, subscription);
70+
log.info("Subscribed to topic [chainTaskId:{}, topic:{}]", chainTaskId, topic);
71+
});
7172
}
7273

7374
/**

src/test/java/com/iexec/worker/pubsub/SubscriptionServiceTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.springframework.context.ApplicationEventPublisher;
3737
import org.springframework.messaging.simp.stomp.StompSession.Subscription;
3838

39+
import java.util.Optional;
40+
3941
public class SubscriptionServiceTests {
4042

4143
@Mock
@@ -50,7 +52,8 @@ public class SubscriptionServiceTests {
5052

5153
private static final String WORKER_WALLET_ADDRESS = "0x1234";
5254
private static final String CHAIN_TASK_ID = "chaintaskid";
53-
private static final Subscription SUBSCRIPTION = mock(Subscription.class);
55+
private static final Optional<Subscription> SUBSCRIPTION =
56+
Optional.of(mock(Subscription.class));
5457

5558
@Before
5659
public void init() {
@@ -87,13 +90,13 @@ public void shouldUnsubscribeFromTopic() {
8790
assertThat(subscriptionService.isSubscribedToTopic(CHAIN_TASK_ID)).isTrue();
8891
subscriptionService.unsubscribeFromTopic(CHAIN_TASK_ID);
8992
assertThat(subscriptionService.isSubscribedToTopic(CHAIN_TASK_ID)).isFalse();
90-
verify(SUBSCRIPTION, times(1)).unsubscribe();
93+
verify(SUBSCRIPTION.get(), times(1)).unsubscribe();
9194
}
9295

9396
@Test
9497
public void shouldNotUnsubscribeFromInexistentTopic() {
9598
assertThat(subscriptionService.isSubscribedToTopic(CHAIN_TASK_ID)).isFalse();
9699
subscriptionService.unsubscribeFromTopic(CHAIN_TASK_ID);
97-
verify(SUBSCRIPTION, never()).unsubscribe();
100+
verify(SUBSCRIPTION.get(), never()).unsubscribe();
98101
}
99102
}

0 commit comments

Comments
 (0)