Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove open with retry in test logic and remove dead code #569

Merged
merged 2 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class DeviceEmulator
this.client = client;
}

void setup() throws InterruptedException
void setup() throws IOException
{
try
{
Expand All @@ -72,7 +72,7 @@ void setup() throws InterruptedException

if (this.client != null)
{
IotHubServicesCommon.openClientWithRetry(this.client);
this.client.open();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void sendMessages(InternalClient client,
{
try
{
openClientWithRetry(client);
client.open();
if (statusUpdates != null)
{
confirmOpenStabilized(statusUpdates, 120000, client);
Expand Down Expand Up @@ -214,7 +214,7 @@ public static void sendExpiredMessageExpectingMessageExpiredCallback(InternalCli
expiredMessage.setAbsoluteExpiryTime(1); //setting this to 0 causes the message to never expire
Success messageSentExpiredCallback = new Success();

openClientWithRetry(client);
client.open();
client.sendEventAsync(expiredMessage, new EventCallback(IotHubStatusCode.MESSAGE_EXPIRED), messageSentExpiredCallback);

long startTime = System.currentTimeMillis();
Expand Down Expand Up @@ -256,7 +256,7 @@ public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeR
}
}, new Object());

openClientWithRetry(client);
client.open();

client.sendEventAsync(errorInjectionMessage, new EventCallback(null), new Success());

Expand Down Expand Up @@ -321,76 +321,6 @@ private static boolean isErrorInjectionMessage(MessageAndResult messageAndResult
return false;
}

public static void openClientWithRetry(InternalClient client) throws InterruptedException
{
//Check again
int count = 0;
boolean clientOpenSucceeded = false;
long startTime = System.currentTimeMillis();
while (!clientOpenSucceeded)
{
if (System.currentTimeMillis() - startTime > OPEN_RETRY_TIMEOUT)
{
Assert.fail(buildExceptionMessage("Timed out trying to open the client " + count, client));
}

try
{
count++;
client.open();
clientOpenSucceeded = true;
}
catch (IOException e)
{
//ignore and try again
System.out.println("Encountered exception while opening device client, retrying...: " + Tools.getStackTraceFromThrowable(e));
try
{
client.closeNow();
}
catch (IOException ioException)
{
System.out.println("Failed to close client: " + Tools.getStackTraceFromThrowable(ioException));
}
Thread.sleep(400);
}
}
}

public static void openTransportClientWithRetry(TransportClient client, Collection<InternalClient> clients) throws InterruptedException
{
boolean clientOpenSucceeded = false;
long startTime = System.currentTimeMillis();
while (!clientOpenSucceeded)
{
if (System.currentTimeMillis() - startTime > OPEN_RETRY_TIMEOUT)
{
Assert.fail(CorrelationDetailsLoggingAssert.buildExceptionMessage("Timed out trying to open the transport client", clients));
}

try
{
client.open();
clientOpenSucceeded = true;
}
catch (IOException e)
{
//ignore and try again
System.out.println("Encountered exception while opening transport client, retrying...: " + Tools.getStackTraceFromThrowable(e));

try
{
client.closeNow();
}
catch (IOException ioException)
{
System.out.println("Failed to close client: " + Tools.getStackTraceFromThrowable(ioException));
}
Thread.sleep(400);
}
}
}

public static void waitForStabilizedConnection(List<Pair<IotHubConnectionStatus, Throwable>> actualStatusUpdates, long timeout, InternalClient client) throws InterruptedException
{
//Wait until error injection takes effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class DeviceMethodCommon extends IntegrationTest
protected static final String PAYLOAD_STRING = "This is a valid payload";

protected static final int NUMBER_INVOKES_PARALLEL = 10;
protected static final int INTERTEST_GUARDIAN_DELAY_MILLISECONDS = 0;
// How much to wait until a message makes it to the server, in milliseconds
protected static final Integer SEND_TIMEOUT_MILLISECONDS = 60000;

Expand Down Expand Up @@ -284,18 +283,8 @@ public void cleanToStart() throws Exception
}

@After
public void afterTest() throws IOException, IotHubException
public void afterTest()
{
try
{
Thread.sleep(INTERTEST_GUARDIAN_DELAY_MILLISECONDS);
}
catch (Exception e)
{
e.printStackTrace();
fail("Unexpected exception encountered");
}

this.testInstance.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class DeviceTwinCommon extends IntegrationTest
protected static final Integer PAGE_SIZE = 2;

protected static String iotHubConnectionString = "";
protected static final int INTERTEST_GUARDIAN_DELAY_MILLISECONDS = 0;

// Constants used in for Testing
protected static final String PROPERTY_KEY = "Key";
Expand Down Expand Up @@ -276,7 +275,7 @@ else if (this.testInstance.authenticationType == SELF_SIGNED)
false);
}
}
IotHubServicesCommon.openClientWithRetry(internalClient);
internalClient.open();
if (internalClient instanceof DeviceClient)
{
((DeviceClient) internalClient).startDeviceTwin(new DeviceTwinStatusCallBack(), deviceState, deviceState.dCDeviceForTwin, deviceState);
Expand Down Expand Up @@ -471,27 +470,16 @@ else if (this.testInstance.authenticationType == SELF_SIGNED)
}

@After
public void tearDownNewDeviceAndModule() throws IOException, IotHubException
public void tearDownNewDeviceAndModule()
{
tearDownTwin(deviceUnderTest);

try
{
tearDownTwin(deviceUnderTest);
registryManager.removeDevice(deviceUnderTest.sCDeviceForRegistryManager.getDeviceId());
}
catch (Exception e)
{

}

try
{
Thread.sleep(INTERTEST_GUARDIAN_DELAY_MILLISECONDS);
}
catch (InterruptedException e)
{
e.printStackTrace();
fail(buildExceptionMessage("Unexpected exception encountered", internalClient));
//Don't care if tear down failed. Nightly job will clean up these identities
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ public enum EnrollmentType
public ProvisioningServiceClient provisioningServiceClient = null;
public RegistryManager registryManager = null;

public static final int INTERTEST_GUARDIAN_DELAY_MILLISECONDS = 0;

//sending reported properties for twin operations takes some time to get the appropriate callback
public static final int MAX_TWIN_PROPAGATION_WAIT_SECONDS = 60;

Expand Down Expand Up @@ -185,16 +183,6 @@ public void setUp() throws Exception
@After
public void tearDown()
{
try
{
Thread.sleep(INTERTEST_GUARDIAN_DELAY_MILLISECONDS);
}
catch (InterruptedException e)
{
e.printStackTrace();
fail("Unexpected exception encountered");
}

registryManager.close();
provisioningServiceClient = null;
registryManager = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class ReceiveMessagesCommon extends IntegrationTest

protected static String expectedCorrelationId = "1234";
protected static String expectedMessageId = "5678";
protected static final int INTERTEST_GUARDIAN_DELAY_MILLISECONDS = 0;
protected static final long ERROR_INJECTION_RECOVERY_TIMEOUT = 1 * 60 * 1000; // 1 minute

public ReceiveMessagesTestInstance testInstance;
Expand Down Expand Up @@ -251,18 +250,8 @@ public void setupTest() throws Exception
}

@After
public void tearDownTest() throws IOException, IotHubException
public void tearDownTest()
{
try
{
Thread.sleep(INTERTEST_GUARDIAN_DELAY_MILLISECONDS);
}
catch (InterruptedException e)
{
e.printStackTrace();
TestCase.fail("Unexpected exception encountered");
}

testInstance.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class SendMessagesCommon extends IntegrationTest
protected static final Integer RETRY_MILLISECONDS = 100;

protected static String iotHubConnectionString = "";
protected static final int INTERTEST_GUARDIAN_DELAY_MILLISECONDS = 0;

protected static String hostName;

Expand Down Expand Up @@ -131,7 +130,6 @@ public static void stopProxy()
}
}


protected static Collection inputsCommon() throws IOException, IotHubException, GeneralSecurityException, URISyntaxException, ModuleClientException, InterruptedException
{
return inputsCommon(ClientType.DEVICE_CLIENT, ClientType.MODULE_CLIENT);
Expand Down Expand Up @@ -373,7 +371,7 @@ public testDevice(Device deviceAmqps, IotHubClientProtocol protocol,
public void openConnection() throws IOException, URISyntaxException, InterruptedException
{
client = new DeviceClient(connString, protocol);
IotHubServicesCommon.openClientWithRetry(client);
client.open();
}

public void sendMessages()
Expand Down Expand Up @@ -509,18 +507,8 @@ protected void buildMessageLists()
}

@After
public void tearDownTest() throws IOException, IotHubException
public void tearDownTest()
{
try
{
Thread.sleep(INTERTEST_GUARDIAN_DELAY_MILLISECONDS);
}
catch (InterruptedException e)
{
e.printStackTrace();
fail("Unexpected exception encountered");
}

this.testInstance.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ else if (testInstance.authenticationType == AuthenticationType.SELF_SIGNED)

Thread.sleep(5000);

IotHubServicesCommon.openClientWithRetry(deviceClient);
deviceClient.open();
return deviceClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeR
}
}, null);

IotHubServicesCommon.openClientWithRetry(testInstance.client);
testInstance.client.open();

//act
testInstance.client.subscribeToDeviceMethod(new DeviceMethodCallback(), null, new DeviceMethodStatusCallBack(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ private void sendMessageFromEachClient(List<InternalClient> clients)
}
}

private void openEachClient(List<InternalClient> clients) throws InterruptedException
private void openEachClient(List<InternalClient> clients) throws IOException
{
for (int clientIndex = 0; clientIndex < clients.size(); clientIndex++)
{
IotHubServicesCommon.openClientWithRetry(clients.get(clientIndex));
clients.get(clientIndex).open();
}
}

Expand Down
Loading