本文整理汇总了Java中org.eclipse.paho.client.mqttv3.IMqttAsyncClient类的典型用法代码示例。如果您正苦于以下问题:Java IMqttAsyncClient类的具体用法?Java IMqttAsyncClient怎么用?Java IMqttAsyncClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMqttAsyncClient类属于org.eclipse.paho.client.mqttv3包,在下文中一共展示了IMqttAsyncClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: builderWithMocks
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
private Builder builderWithMocks(final String expectedClientId) {
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
Mockito.when(client.getClientId()).thenReturn(expectedClientId);
final CloseFactory closeFactory = Mockito.mock(CloseFactory.class);
final ConnectFactory connectFactory = Mockito.mock(ConnectFactory.class);
final DisconnectFactory disconnectFactory = Mockito.mock(DisconnectFactory.class);
final PublishFactory publishFactory = Mockito.mock(PublishFactory.class);
final SubscribeFactory subscribeFactory = Mockito.mock(SubscribeFactory.class);
final UnsubscribeFactory unsubscribeFactory = Mockito.mock(UnsubscribeFactory.class);
return new PahoObservableMqttClient.Builder(client)
.setCloseFactory(closeFactory)
.setConnectFactory(connectFactory)
.setDisconnectFactory(disconnectFactory)
.setPublishFactory(publishFactory)
.setSubscribeFactory(subscribeFactory)
.setUnsubscribeFactory(unsubscribeFactory);
}
示例2: whenCreateIsCalledThenAnObservableIsReturned
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
final SubscribeFactory factory = new SubscribeFactory(client);
final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
final ArgumentCaptor<IMqttMessageListener[]> messageListener = ArgumentCaptor.forClass(IMqttMessageListener[].class);
final String[] topics = new String[]{ "topic1", "topic2" };
final int[] qos = new int[]{ 1, 2 };
final Flowable<MqttMessage> obs = factory.create(topics, qos, BackpressureStrategy.ERROR);
Assert.assertNotNull(obs);
obs.subscribe();
Mockito.verify(client).subscribe(Mockito.same(topics),
Mockito.same(qos),
Mockito.isNull(),
actionListener.capture(),
messageListener.capture());
Assert.assertTrue(actionListener.getValue() instanceof SubscribeFactory.SubscribeActionListener);
Assert.assertTrue(messageListener.getValue() instanceof SubscriberMqttMessageListener[]);
Assert.assertEquals(2, messageListener.getValue().length);
}
示例3: whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled() throws Throwable {
expectedException.expectCause(isA(MqttException.class));
final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
final ArgumentCaptor<IMqttMessageListener[]> messageListener = ArgumentCaptor.forClass(IMqttMessageListener[].class);
final String[] topics = new String[]{ "topic1", "topic2" };
final int[] qos = new int[]{ 1, 2 };
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
Mockito.when(client.subscribe(Mockito.same(topics),
Mockito.same(qos),
Mockito.isNull(),
actionListener.capture(),
messageListener.capture()))
.thenThrow(new MqttException(MqttException.REASON_CODE_CLIENT_CONNECTED));
final SubscribeFactory factory = new SubscribeFactory(client);
final Flowable<MqttMessage> obs = factory.create(topics, qos, BackpressureStrategy.ERROR);
obs.blockingFirst();
}
示例4: whenCreateIsCalledThenAnObservableIsReturned
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
// Given
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
final PublishFactory factory = new PublishFactory(client);
final String topic = "topic1";
final MqttMessage msg = MqttMessage.create(0, new byte[] { 'a', 'b', 'c' }, 1, true);
final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
// When
final Single<PublishToken> obs = factory.create(topic, msg);
// Then
Assert.assertNotNull(obs);
obs.subscribe();
Mockito.verify(client).publish(Mockito.same(topic),
Mockito.same(msg.getPayload()), Mockito.anyInt(),
Mockito.anyBoolean(), Mockito.any(),
actionListener.capture());
Assert.assertTrue(actionListener.getValue() instanceof PublishFactory.PublishActionListener);
}
示例5: whenCreateIsCalledThenAnObservableIsReturned
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
// Given
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
final UnsubscribeFactory factory = new UnsubscribeFactory(client);
final String[] topics = new String[]{ "topic1", "topic2" };
final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
// When
final Completable obs = factory.create(topics);
// Then
Assert.assertNotNull(obs);
obs.subscribe();
Mockito.verify(client).unsubscribe(Mockito.same(topics), Mockito.isNull(),
actionListener.capture());
Assert.assertTrue(actionListener.getValue() instanceof UnsubscribeFactory.UnsubscribeActionListener);
}
示例6: whenCreateIsCalledThenAnObservableIsReturned
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
// Given
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
final DisconnectFactory factory = new DisconnectFactory(client);
final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
// When
final Completable obs = factory.create();
// Then
Assert.assertNotNull(obs);
obs.subscribe();
Mockito.verify(client).disconnect(Mockito.isNull(),
actionListener.capture());
Assert.assertTrue(actionListener.getValue() instanceof DisconnectFactory.DisconnectActionListener);
}
示例7: stop
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Stop
public void stop() {
LOG.info("Mqttv3Client stoping!");
if (clnt != null) {
for (Entry<String, ObjectPool<IMqttAsyncClient>> entry : clnt.entrySet()) {
try {
entry.getValue().close();
} catch (Exception e) {
LOG.error(e.getMessage(), e.fillInStackTrace());
}
}
clnt = null;
}
LOG.info("Mqttv3Client finish stoping!");
}
示例8: MqttCallBackImpl
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
public MqttCallBackImpl (IMqttAsyncClient client,String clientID,String logLevel,String encoding) {
super(encoding);
this.clientID = clientID;
this.logLevel = logLevel;
this.client = client;
this.encoding = encoding;
}
示例9: Builder
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
public Builder(final IMqttAsyncClient client) {
this.client = client;
this.connectOptions = new MqttConnectOptions();
this.closeFactory = new CloseFactory(client);
this.connectFactory = new ConnectFactory(this.client, this.connectOptions);
this.disconnectFactory = new DisconnectFactory(client);
this.publishFactory = new PublishFactory(client);
this.subscribeFactory = new SubscribeFactory(client);
this.unsubscribeFactory = new UnsubscribeFactory(client);
this.backpressureStrategy = BackpressureStrategy.BUFFER;
}
示例10: whenAValidBackpressureStrategyThenTheAccessorReturnsIt
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenAValidBackpressureStrategyThenTheAccessorReturnsIt() throws MqttException {
BackpressureStrategy expected = BackpressureStrategy.BUFFER;
Builder builder = PahoObservableMqttClient.builder(Mockito.mock(IMqttAsyncClient.class))
.setBackpressureStrategy(expected);
Assert.assertNotNull(builder);
Assert.assertNotNull(builder.getBackpressureStrategy());
Assert.assertEquals(expected, builder.getBackpressureStrategy());
}
示例11: whenGetClientIdIsCalledItReturnsPahoClientId
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenGetClientIdIsCalledItReturnsPahoClientId() {
final String expectedClientId = "clientId";
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
Mockito.when(client.getClientId()).thenReturn(expectedClientId);
final Builder builder = new PahoObservableMqttClient.Builder(client);
final PahoObservableMqttClient target = builder.build();
Assert.assertEquals(expectedClientId, target.getClientId());
}
示例12: whenGetBrokerUriIsCalledItReturnsPahoServerUrl
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenGetBrokerUriIsCalledItReturnsPahoServerUrl() {
final String expectedBrokerUri = "brokerUri";
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
Mockito.when(client.getServerURI()).thenReturn(expectedBrokerUri);
final Builder builder = new PahoObservableMqttClient.Builder(client);
final PahoObservableMqttClient target = builder.build();
Assert.assertEquals(expectedBrokerUri, target.getBrokerUri());
}
示例13: whenThePahoClientIsConnectedIsConnectedReturnsTrue
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenThePahoClientIsConnectedIsConnectedReturnsTrue() {
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
Mockito.when(client.isConnected()).thenReturn(true);
final Builder builder = new PahoObservableMqttClient.Builder(client);
final PahoObservableMqttClient target = builder.build();
Assert.assertEquals(true, target.isConnected());
}
示例14: whenCreateIsCalledThenAnObservableIsReturned
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
final MqttConnectOptions options = Mockito.mock(MqttConnectOptions.class);
final ConnectFactory factory = new ConnectFactory(client, options);
final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
final Completable obs = factory.create();
Assert.assertNotNull(obs);
obs.subscribe();
Mockito.verify(client).connect(Mockito.same(options), Mockito.isNull(),
actionListener.capture());
Assert.assertTrue(actionListener.getValue() instanceof ConnectFactory.ConnectActionListener);
}
示例15: whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled() throws Throwable {
expectedException.expectCause(isA(MqttException.class));
final MqttConnectOptions options = Mockito.mock(MqttConnectOptions.class);
final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
Mockito.when(client.connect(Mockito.same(options), Mockito.isNull(),
Mockito.any(ConnectFactory.ConnectActionListener.class)))
.thenThrow(new MqttException(MqttException.REASON_CODE_CLIENT_CONNECTED));
final ConnectFactory factory = new ConnectFactory(client, options);
final Completable obs = factory.create();
obs.blockingAwait();
}