use of org.eclipse.leshan.core.request.RegisterRequest in project leshan by eclipse.
the class FailingTest method sync_send_with_acknowleged_request_without_response.
@Test
public void sync_send_with_acknowleged_request_without_response() throws Exception {
// Register client
LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null, Link.parse("</1>,</2>,</3>".getBytes()), null));
client.expectResponse().go();
helper.waitForRegistration(1);
// Send read
Future<ReadResponse> future = Executors.newSingleThreadExecutor().submit(new Callable<ReadResponse>() {
@Override
public ReadResponse call() throws Exception {
// send a request with 3 seconds timeout
return helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000);
}
});
// Acknowledge the response
client.expectRequest().storeMID("R").go();
client.sendEmpty(Type.ACK).loadMID("R").go();
// Request should timedout in ~3s as we send the ACK
Thread.sleep(1500);
Assert.assertFalse("we should still wait for response", future.isDone());
ReadResponse response = future.get(2000, TimeUnit.MILLISECONDS);
Assert.assertNull("we should timeout", response);
}
use of org.eclipse.leshan.core.request.RegisterRequest in project leshan by eclipse.
the class FailingTest method async_send_with_acknowleged_request_without_response.
@Test
public void async_send_with_acknowleged_request_without_response() throws Exception {
// register client
LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null, Link.parse("</1>,</2>,</3>".getBytes()), null));
client.expectResponse().go();
helper.waitForRegistration(1);
// send read
Callback<ReadResponse> callback = new Callback<ReadResponse>();
helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000l, callback, callback);
// Acknowledge the response
client.expectRequest().storeMID("R").go();
client.sendEmpty(Type.ACK).loadMID("R").go();
// Request should timedout in ~3s as we send a ack
Thread.sleep(1500);
Assert.assertTrue("we should still wait for response", callback.getException() == null);
callback.waitForResponse(2000);
Assert.assertTrue("we should timeout", callback.getException() instanceof TimeoutException);
}
use of org.eclipse.leshan.core.request.RegisterRequest in project leshan by eclipse.
the class RegistrationEngine method register.
private boolean register() throws InterruptedException {
ServersInfo serversInfo = ServersInfoExtractor.getInfo(objectEnablers);
DmServerInfo dmInfo = serversInfo.deviceMangements.values().iterator().next();
if (dmInfo == null) {
LOG.error("Trying to register device but there is no LWM2M server config.");
return false;
}
// send register request
LOG.info("Trying to register to {} ...", dmInfo.getFullUri());
RegisterRequest regRequest = new RegisterRequest(endpoint, dmInfo.lifetime, LwM2m.VERSION, dmInfo.binding, null, LinkFormatHelper.getClientDescription(objectEnablers.values(), null), additionalAttributes);
RegisterResponse response = sender.send(dmInfo.getAddress(), dmInfo.isSecure(), regRequest, DEFAULT_TIMEOUT);
if (response == null) {
registrationID = null;
LOG.error("Registration failed: Timeout.");
if (observer != null) {
observer.onRegistrationTimeout(dmInfo);
}
} else if (response.isSuccess()) {
registrationID = response.getRegistrationID();
LOG.info("Registered with location '{}'.", response.getRegistrationID());
// update every lifetime period
scheduleUpdate(dmInfo);
if (observer != null) {
observer.onRegistrationSuccess(dmInfo, response.getRegistrationID());
}
} else {
registrationID = null;
LOG.error("Registration failed: {} {}.", response.getCode(), response.getErrorMessage());
if (observer != null) {
observer.onRegistrationFailure(dmInfo, response.getCode(), response.getErrorMessage());
}
}
return registrationID != null;
}
use of org.eclipse.leshan.core.request.RegisterRequest in project leshan by eclipse.
the class FailingTest method async_send_without_acknowleged.
@Test
public void async_send_without_acknowleged() throws Exception {
// register client
LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null, Link.parse("</1>,</2>,</3>".getBytes()), null));
client.expectResponse().go();
helper.waitForRegistration(1);
// send read
Callback<ReadResponse> callback = new Callback<ReadResponse>();
helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000l, callback, callback);
// Request should timedout in ~1s we don't send ACK
callback.waitForResponse(1500);
Assert.assertTrue("we should timeout", callback.getException() instanceof TimeoutException);
}
use of org.eclipse.leshan.core.request.RegisterRequest in project leshan by eclipse.
the class FailingTest method sync_send_without_acknowleged.
@Test
public void sync_send_without_acknowleged() throws Exception {
// Register client
LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null, Link.parse("</1>,</2>,</3>".getBytes()), null));
client.expectResponse().go();
helper.waitForRegistration(1);
// Send read
Future<ReadResponse> future = Executors.newSingleThreadExecutor().submit(new Callable<ReadResponse>() {
@Override
public ReadResponse call() throws Exception {
// send a request with 3 seconds timeout
return helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000);
}
});
// Request should timedout in ~1s we don't send ACK
ReadResponse response = future.get(1500, TimeUnit.MILLISECONDS);
Assert.assertNull("we should timeout", response);
}
Aggregations