# HG changeset patch # User dadubrow # Date 1261169332 21600 # Node ID a6f7bb38d188e37c5c56c51ed98f4f38dd3a899d # Parent 72c9852d35bbf25c1d219f038f4f92a00f5a8228 add test discovery agent diff -r 72c9852d35bb -r a6f7bb38d188 connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml --- a/connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml Fri Dec 18 14:48:04 2009 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml Fri Dec 18 14:48:52 2009 -0600 @@ -63,5 +63,11 @@ class="com.nokia.carbide.remoteconnections.tests.extensions.DefaultProvidingTCPIPService"> + + + + diff -r 72c9852d35bb -r a6f7bb38d188 connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/discovery/RandomDiscoveryAgent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/discovery/RandomDiscoveryAgent.java Fri Dec 18 14:48:52 2009 -0600 @@ -0,0 +1,116 @@ +/** +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.remoteconnections.tests.discovery; + +import java.net.URL; +import java.util.HashSet; +import java.util.Map; +import java.util.Random; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; + +import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2; +import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent; +import com.nokia.carbide.remoteconnections.tests.extensions.IntervalConnectionType; +import com.nokia.carbide.remoteconnections.tests.extensions.TestFilter; + +public class RandomDiscoveryAgent implements IDeviceDiscoveryAgent { + private static final String CONNECTION_TYPE = + "com.nokia.carbide.remoteconnections.tests.extensions.IntervalConnectionType"; + private Random random = new Random(); + private Set connections = new HashSet(); + private IConnectionsManager manager = RemoteConnectionsActivator.getConnectionsManager(); + + private final class DiscoveryThread extends Thread { + private static final int MAX = 60000; + private static final int MIN = 10000; + private volatile boolean keepRunning; + + public void run() { + keepRunning = true; + while (keepRunning) { + try { + sleep(getRandomCreationIntervalMs()); + } catch (InterruptedException e) { + keepRunning = false; + } + if (getRandomIntBetween(0, connections.size() + 1) == 0) { + createNewConnection(); + } + else if (!connections.isEmpty()) { + IConnection2 connection = connections.iterator().next(); + connections.remove(connection); + manager.disconnect(connection); + } + } + } + + private int getRandomCreationIntervalMs() { + return getRandomIntBetween(MIN, MAX); + } + + public void stopRunning() { + keepRunning = false; + } + } + + private DiscoveryThread thread = new DiscoveryThread(); + + public URL getInformation() { + return null; + } + + private void createNewConnection() { + IConnectionType connectionType = + RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionType(CONNECTION_TYPE); + IConnectionFactory factory = connectionType.getConnectionFactory(); + Map settings = factory.getSettingsFromUI(); + String val = getRandomIntervalString(); + settings.put(IntervalConnectionType.KEY, val); + IConnection2 connection = (IConnection2) factory.createConnection(settings); + connection.setDisplayName(connection.getConnectionType().getDisplayName() + " " + val + " ms"); + connection.setDynamic(true); + connections.add(connection); + manager.addConnection(connection); + manager.setDefaultConnection(connection); + } + + private String getRandomIntervalString() { + int r = getRandomIntBetween(1000, 30000); + return Integer.toString(r); + } + + private int getRandomIntBetween(int min, int max) { + return (Math.abs(random.nextInt()) % (max - min)) + min; + } + + public void start() throws CoreException { + if (TestFilter.isTest) + thread.start(); + } + + public void stop() throws CoreException { + thread.stopRunning(); + } + +} diff -r 72c9852d35bb -r a6f7bb38d188 connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/IntervalConnection.java --- a/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/IntervalConnection.java Fri Dec 18 14:48:04 2009 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/IntervalConnection.java Fri Dec 18 14:48:52 2009 -0600 @@ -18,75 +18,22 @@ package com.nokia.carbide.remoteconnections.tests.extensions; -import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import java.util.HashMap; +import java.util.Map; + +import com.nokia.carbide.remoteconnections.interfaces.AbstractConnection; import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; import com.nokia.cpp.internal.api.utils.core.Check; -import java.util.Collections; -import java.util.Map; - -public class IntervalConnection implements IConnection { +public class IntervalConnection extends AbstractConnection { private int msInterval; - private String id; - private String name; - private IConnectionType connectionType; public IntervalConnection(IConnectionType connectionType) { - this.connectionType = connectionType; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#dispose() - */ - public void dispose() { - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#getConnectionType() - */ - public IConnectionType getConnectionType() { - return connectionType; + super(connectionType, new HashMap()); + getSettings().put(IntervalConnectionType.KEY, Integer.toString(msInterval)); } - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#getIdentifier() - */ - public String getIdentifier() { - return id; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.interfaces.IConnection#getDisplayName() - */ - public String getDisplayName() { - return name; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.interfaces.IConnection#setDisplayName(java.lang.String) - */ - public void setDisplayName(String name) { - this.name = name; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#getSettings() - */ - public Map getSettings() { - return Collections.singletonMap(IntervalConnectionType.KEY, Integer.toString(msInterval)); - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#setIdentifier(java.lang.String) - */ - public void setIdentifier(String id) { - this.id = id; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#updateSettings(java.util.Map) - */ public void updateSettings(Map newSettings) { Check.checkContract(newSettings.containsKey(IntervalConnectionType.KEY)); String string = newSettings.get(IntervalConnectionType.KEY); @@ -103,9 +50,10 @@ @Override public String toString() { - return name; + return getDisplayName(); } public void useConnection(boolean use) { + // TODO Auto-generated method stub } }