Search in sources :

Example 81 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project voltdb by VoltDB.

the class LoadTableLoader method run.

@Override
public void run() {
    // ratio of upsert for @Load*Table
    final float upsertratio = 0.50F;
    // ratio of upsert to an existing table for @Load*Table
    final float upserthitratio = 0.20F;
    CopyAndDeleteDataTask cdtask = new CopyAndDeleteDataTask();
    cdtask.start();
    long p;
    List<Long> cidList = new ArrayList<Long>(batchSize);
    List<Long> timeList = new ArrayList<Long>(batchSize);
    try {
        // pick up where we left off
        ClientResponse cr = TxnId2Utils.doAdHoc(client, "select nvl(max(cid)+1,0) from " + m_tableName + ";");
        p = cr.getResults()[0].asScalarLong();
        while (m_shouldContinue.get()) {
            //1 in 3 gets copied and then deleted after leaving some data
            byte shouldCopy = (byte) (m_random.nextInt(3) == 0 ? 1 : 0);
            byte upsertMode = (byte) (m_random.nextFloat() < upsertratio ? 1 : 0);
            byte upsertHitMode = (byte) ((upsertMode != 0) && (m_random.nextFloat() < upserthitratio) ? 1 : 0);
            CountDownLatch latch = new CountDownLatch(batchSize);
            final BlockingQueue<Long> lcpDelQueue = new LinkedBlockingQueue<Long>();
            cidList.clear();
            timeList.clear();
            // try to insert/upsert batchSize random rows
            for (int i = 0; i < batchSize; i++) {
                m_table.clearRowData();
                m_permits.acquire();
                //Increment p so that we always get new key.
                p++;
                long nanotime = System.nanoTime();
                m_table.addRow(p, p + nanotime, nanotime);
                cidList.add(p);
                timeList.add(nanotime);
                BlockingQueue<Long> wrkQueue;
                if (shouldCopy != 0) {
                    wrkQueue = lcpDelQueue;
                } else {
                    wrkQueue = onlyDelQueue;
                }
                boolean success;
                try {
                    if (!m_isMP) {
                        Object rpartitionParam = VoltType.valueToBytes(m_table.fetchRow(0).get(m_partitionedColumnIndex, VoltType.BIGINT));
                        if (upsertHitMode != 0) {
                            // for test upsert an existing row, insert it and then upsert same row again.
                            // only insert
                            success = client.callProcedure(new InsertCallback(latch, p, shouldCopy, wrkQueue, unkQueue, loadTxnCount, (byte) 1), m_procName, rpartitionParam, m_tableName, (byte) 0, m_table);
                        } else {
                            // insert or upsert
                            success = client.callProcedure(new InsertCallback(latch, p, shouldCopy, wrkQueue, unkQueue, loadTxnCount, (byte) 2), m_procName, rpartitionParam, m_tableName, upsertMode, m_table);
                        }
                    } else {
                        if (upsertHitMode != 0) {
                            // only insert
                            success = client.callProcedure(new InsertCallback(latch, p, shouldCopy, wrkQueue, unkQueue, loadTxnCount, (byte) 3), m_procName, m_tableName, (byte) 0, m_table);
                        } else {
                            // insert or upsert
                            success = client.callProcedure(new InsertCallback(latch, p, shouldCopy, wrkQueue, unkQueue, loadTxnCount, (byte) 4), m_procName, m_tableName, upsertMode, m_table);
                        }
                    }
                    if (!success) {
                        hardStop("Failed to insert upsert for: " + p);
                    }
                    if (m_slowFlight)
                        Thread.sleep(slowDownDelayMs);
                } catch (NoConnectionsException e) {
                    //drop this lcid on the floor, we'll just move on
                    setSlowFlight();
                } catch (Exception e) {
                    hardStop(e);
                }
            }
            log.debug("Waiting for all inserts for @Load* done.");
            //Wait for all @Load{SP|MP}Done
            latch.await();
            log.debug("Done Waiting for all inserts for @Load* done.");
            // try to upsert if want the collision
            if (upsertHitMode != 0) {
                CountDownLatch upserHitLatch = new CountDownLatch(batchSize * upsertHitMode);
                BlockingQueue<Long> cpywrkQueue = new LinkedBlockingQueue<Long>();
                BlockingQueue<Long> cpyunkQueue = new LinkedBlockingQueue<Long>();
                for (int i = 0; i < batchSize; i++) {
                    m_table.clearRowData();
                    m_permits.acquire();
                    m_table.addRow(cidList.get(i), cidList.get(i) + timeList.get(i), timeList.get(i));
                    boolean success;
                    try {
                        if (!m_isMP) {
                            Object rpartitionParam = VoltType.valueToBytes(m_table.fetchRow(0).get(m_partitionedColumnIndex, VoltType.BIGINT));
                            // upsert only
                            success = client.callProcedure(new InsertCallback(upserHitLatch, p, shouldCopy, cpywrkQueue, cpyunkQueue, upsertTxnCount, (byte) 5), m_procName, rpartitionParam, m_tableName, (byte) 1, m_table);
                        } else {
                            // upsert only
                            success = client.callProcedure(new InsertCallback(upserHitLatch, p, shouldCopy, cpywrkQueue, cpyunkQueue, upsertTxnCount, (byte) 6), m_procName, m_tableName, (byte) 1, m_table);
                        }
                        if (!success) {
                            hardStop("Failed to invoke upsert for: " + cidList.get(i));
                        }
                        if (m_slowFlight)
                            Thread.sleep(slowDownDelayMs);
                    } catch (NoConnectionsException e) {
                        //drop this lcid on the floor, we'll just move on
                        setSlowFlight();
                    } catch (Exception e) {
                        hardStop(e);
                    }
                }
                log.debug("Waiting for all upsert for @Load* done.");
                //Wait for all additional upsert @Load{SP|MP}Done
                upserHitLatch.await();
                log.debug("Done Waiting for all upsert for @Load* done.");
            }
            //log.info("to copy: " + lcpDelQueue.toString());
            cpyQueue.addAll(lcpDelQueue);
            try {
                long nextRowCount = TxnId2Utils.getRowCount(client, m_tableName);
                long nextCpRowCount = TxnId2Utils.getRowCount(client, "cp" + m_tableName);
                // report counts of successful txns
                log.info("LoadTableLoader rowcounts " + nextRowCount + "/" + nextCpRowCount + " Insert/Upsert txs: " + loadTxnCount[0] + " UpsertHit txs: " + upsertTxnCount[0] + " Copy txs: " + copyTxnCount + " Delete txn: " + deleteTxnCount);
            } catch (Exception e) {
                hardStop("getrowcount exception", e);
            }
            if (onlyDelQueue.size() > 0 && m_shouldContinue.get()) {
                List<Long> workList = new ArrayList<Long>();
                onlyDelQueue.drainTo(workList);
                //log.info("from deleteonly to delete: " + workList.toString());
                CountDownLatch odlatch = new CountDownLatch(workList.size());
                for (Long lcid : workList) {
                    try {
                        boolean success;
                        success = client.callProcedure(new DeleteCallback(odlatch, lcid, onlyDelQueue, unkQueue, null, delUnkQueue, 1, (byte) 1), m_onlydelprocName, lcid);
                        if (!success) {
                            hardStop("Failed to invoke delete for: " + lcid);
                        }
                        if (m_slowFlight)
                            Thread.sleep(slowDownDelayMs);
                    } catch (NoConnectionsException e) {
                        //requeue for next time
                        onlyDelQueue.add(lcid);
                        setSlowFlight();
                    } catch (Exception e) {
                        hardStop(e);
                    }
                }
                odlatch.await();
            }
            if (unkQueue.size() > 0 && m_shouldContinue.get()) {
                List<Long> workList = new ArrayList<Long>();
                unkQueue.drainTo(workList);
                //log.info("from unknownqueue to delete: " + workList.toString());
                CountDownLatch odlatch = new CountDownLatch(workList.size());
                for (Long lcid : workList) {
                    try {
                        boolean success;
                        success = client.callProcedure(new DeleteCallback(odlatch, lcid, unkQueue, null, null, unkQueue, -1, (byte) 3), m_onlydelprocName, lcid);
                        if (!success) {
                            hardStop("Failed to invoke delete for: " + lcid);
                        }
                        if (m_slowFlight)
                            Thread.sleep(slowDownDelayMs);
                    } catch (NoConnectionsException e) {
                        //requeue for next time
                        unkQueue.add(lcid);
                        setSlowFlight();
                    } catch (Exception e) {
                        hardStop(e);
                    }
                }
                odlatch.await();
            }
        }
    } catch (Exception e) {
        // on exception, log and end the thread, but don't kill the process
        if (e instanceof ProcCallException)
            log.error(((ProcCallException) e).getClientResponse().toString());
        hardStop("LoadTableLoader failed a procedure call for table " + m_tableName + " and the thread will now stop.", e);
    } finally {
        cdtask.shutdown();
        try {
            cdtask.join();
        } catch (InterruptedException ex) {
            log.error("CopyDelete Task was stopped.", ex);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IOException(java.io.IOException) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 82 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppDataUsage method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Bundle args = getArguments();
    try {
        mStatsSession = services.mStatsService.openSession();
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    }
    mAppItem = (args != null) ? (AppItem) args.getParcelable(ARG_APP_ITEM) : null;
    mTemplate = (args != null) ? (NetworkTemplate) args.getParcelable(ARG_NETWORK_TEMPLATE) : null;
    mPolicyManager = NetworkPolicyManager.from(getActivity());
    if (mTemplate == null) {
        Context context = getContext();
        mTemplate = DataUsageSummary.getDefaultTemplate(context, DataUsageSummary.getDefaultSubscriptionId(context));
    }
    if (mAppItem == null) {
        int uid = (args != null) ? args.getInt(AppInfoBase.ARG_PACKAGE_UID, -1) : getActivity().getIntent().getIntExtra(AppInfoBase.ARG_PACKAGE_UID, -1);
        if (uid == -1) {
            // TODO: Log error.
            getActivity().finish();
        } else {
            addUid(uid);
            mAppItem = new AppItem(uid);
            mAppItem.addUid(uid);
        }
    } else {
        for (int i = 0; i < mAppItem.uids.size(); i++) {
            addUid(mAppItem.uids.keyAt(i));
        }
    }
    addPreferencesFromResource(R.xml.app_data_usage);
    mTotalUsage = findPreference(KEY_TOTAL_USAGE);
    mForegroundUsage = findPreference(KEY_FOREGROUND_USAGE);
    mBackgroundUsage = findPreference(KEY_BACKGROUND_USAGE);
    mCycle = (SpinnerPreference) findPreference(KEY_CYCLE);
    mCycleAdapter = new CycleAdapter(getContext(), mCycle, mCycleListener, false);
    if (mAppItem.key > 0) {
        if (mPackages.size() != 0) {
            PackageManager pm = getPackageManager();
            try {
                ApplicationInfo info = pm.getApplicationInfo(mPackages.valueAt(0), 0);
                mIcon = info.loadIcon(pm);
                mLabel = info.loadLabel(pm);
                mPackageName = info.packageName;
            } catch (PackageManager.NameNotFoundException e) {
            }
        }
        if (!UserHandle.isApp(mAppItem.key)) {
            removePreference(KEY_UNRESTRICTED_DATA);
            removePreference(KEY_RESTRICT_BACKGROUND);
            removePreference(KEY_RESTRICT_ALL_DATA);
            removePreference(KEY_RESTRICT_ALL_WIFI);
        } else {
            mRestrictBackground = (SwitchPreference) findPreference(KEY_RESTRICT_BACKGROUND);
            mRestrictBackground.setOnPreferenceChangeListener(this);
            mUnrestrictedData = (SwitchPreference) findPreference(KEY_UNRESTRICTED_DATA);
            mUnrestrictedData.setOnPreferenceChangeListener(this);
            mRestrictAllData = (SwitchPreference) findPreference(KEY_RESTRICT_ALL_DATA);
            mRestrictAllData.setOnPreferenceChangeListener(this);
            mRestrictAllWifi = (SwitchPreference) findPreference(KEY_RESTRICT_ALL_WIFI);
            mRestrictAllWifi.setOnPreferenceChangeListener(this);
        }
        mDataSaverBackend = new DataSaverBackend(getContext());
        mAppSettings = findPreference(KEY_APP_SETTINGS);
        mAppSettingsIntent = new Intent(Intent.ACTION_MANAGE_NETWORK_USAGE);
        mAppSettingsIntent.addCategory(Intent.CATEGORY_DEFAULT);
        PackageManager pm = getPackageManager();
        boolean matchFound = false;
        for (String packageName : mPackages) {
            mAppSettingsIntent.setPackage(packageName);
            if (pm.resolveActivity(mAppSettingsIntent, 0) != null) {
                matchFound = true;
                break;
            }
        }
        if (!matchFound) {
            removePreference(KEY_APP_SETTINGS);
            mAppSettings = null;
        }
        if (mPackages.size() > 1) {
            mAppList = (PreferenceCategory) findPreference(KEY_APP_LIST);
            final int packageSize = mPackages.size();
            final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(packageSize);
            final ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, workQueue);
            for (int i = 1; i < mPackages.size(); i++) {
                final AppPrefLoader loader = new AppPrefLoader();
                loader.executeOnExecutor(executor, mPackages.valueAt(i));
            }
        } else {
            removePreference(KEY_APP_LIST);
        }
    } else {
        final Context context = getActivity();
        UidDetail uidDetail = new UidDetailProvider(context).getUidDetail(mAppItem.key, true);
        mIcon = uidDetail.icon;
        mLabel = uidDetail.label;
        mPackageName = context.getPackageName();
        removePreference(KEY_UNRESTRICTED_DATA);
        removePreference(KEY_APP_SETTINGS);
        removePreference(KEY_RESTRICT_BACKGROUND);
        removePreference(KEY_APP_LIST);
        removePreference(KEY_RESTRICT_ALL_DATA);
        removePreference(KEY_RESTRICT_ALL_WIFI);
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) NetworkTemplate(android.net.NetworkTemplate) UidDetail(com.android.settingslib.net.UidDetail) PackageManager(android.content.pm.PackageManager) AppItem(com.android.settingslib.AppItem) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RemoteException(android.os.RemoteException) UidDetailProvider(com.android.settingslib.net.UidDetailProvider)

Example 83 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project ACS by ACS-Community.

the class ManagerImpl method initialize.

/**
	 * Initializes Manager.
	 * @param	prevayler			implementation of prevayler system
	 * @param	context				remote directory implementation
	 */
public void initialize(Prevayler prevayler, CDBAccess cdbAccess, Context context, final Logger logger, ManagerContainerServices managerContainerServices) {
    this.prevayler = prevayler;
    this.remoteDirectory = context;
    this.logger = logger;
    // needs to be done here, since deserialization is used
    initializeDefaultConfiguration();
    if (cdbAccess != null)
        setCDBAccess(cdbAccess);
    readManagerConfiguration();
    componentsLock = (ProfilingReentrantLock.isProfilingEnabled ? new ProfilingReentrantLock("componentsLock") : new ReentrantLock());
    random = new Random();
    heartbeatTask = new Timer(true);
    delayedDeactivationTask = new Timer(true);
    containerLoggedInMonitor = new Object();
    activationSynchronization = new HashMap<String, ReferenceCountingLock>();
    activationPendingRWLock = new ReaderPreferenceReadWriteLock();
    shutdown = new AtomicBoolean(false);
    threadPool = new ThreadPoolExecutor(poolThreads, poolThreads, Long.MAX_VALUE, TimeUnit.NANOSECONDS, new LinkedBlockingQueue(), new DaemonThreadFactory("managerThreadPool"));
    managerCache = new HashMap<String, Manager>();
    pendingActivations = new HashMap<String, ComponentInfo>();
    pendingContainerShutdown = Collections.synchronizedSet(new HashSet<String>());
    pendingContainerAsyncRequests = new HashMap<String, Deque<ComponentInfoCompletionCallback>>();
    clientMessageQueue = new HashMap<Client, LinkedList<ClientMessageTask>>();
    groupedNotifyTaskMap = new HashMap<Object, GroupedNotifyTask>();
    threadsUsedPercentage = new AtomicInteger(0);
    // create threads
    threadPool.prestartAllCoreThreads();
    // read CDB startup
    try {
        String componentSpec = System.getProperty(NAME_CDB_COMPONENTSPEC);
        if (componentSpec != null) {
            cdbActivation = new ComponentSpec(componentSpec);
            logger.log(Level.INFO, "Using CDB component specification: '" + cdbActivation + "'.");
        }
    } catch (Throwable t) {
        logger.log(Level.WARNING, "Failed to parse '" + NAME_CDB_COMPONENTSPEC + "' variable, " + t.getMessage(), t);
    }
    // check load balancing strategy
    checkLoadBalancingStrategy();
    // establish connect to the alarm system
    try {
        alarmSource = new AlarmSourceImpl(managerContainerServices);
        alarmSource.start();
    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Failed to initialize Alarm System Interface " + ex.getMessage(), ex);
        alarmSource = null;
    }
    // register ping tasks
    initializePingTasks();
    // handle monitoring removal task
    final long timeInMs = enableHandleMonitoringDurationMins * 60L * 1000;
    if (enableHandleMonitoring && enableHandleMonitoringDurationMins > 0) {
        heartbeatTask.schedule(new TimerTask() {

            @Override
            public void run() {
                try {
                    logHandleCleanup(timeInMs);
                } catch (Throwable th) {
                    logger.log(Level.SEVERE, "Unexpected exception in handle log cleanup task.", th);
                }
            }
        }, 0, timeInMs);
    }
    // start topology sort manager
    topologySortManager = new ComponentInfoTopologicalSortManager(components, containers, activationPendingRWLock, pendingContainerShutdown, threadPool, logger);
    if (prevayler == null)
        statePersitenceFlag.set(false);
    String enDis = statePersitenceFlag.get() ? "enabled" : "disabled";
    logger.info("Manager initialized with state persistence " + enDis + ".");
}
Also used : DaemonThreadFactory(alma.acs.concurrent.DaemonThreadFactory) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Manager(com.cosylab.acs.maci.Manager) Random(java.util.Random) TimerTask(java.util.TimerTask) AlarmSourceImpl(alma.acs.alarmsystem.source.AlarmSourceImpl) Client(com.cosylab.acs.maci.Client) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque) LinkedList(java.util.LinkedList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timer(java.util.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 84 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project OpenRefine by OpenRefine.

the class ShutdownSignalHandler method init.

public void init(String host, int port) throws Exception {
    logger.info("Starting Server bound to '" + host + ":" + port + "'");
    String memory = Configurations.get("refine.memory");
    if (memory != null) {
        logger.info("refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
    }
    int maxThreads = Configurations.getInteger("refine.queue.size", 30);
    int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
    long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);
    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);
    threadPool = new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);
    this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));
    Connector connector = new SocketConnector();
    connector.setPort(port);
    connector.setHost(host);
    connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time", 60000));
    connector.setStatsOn(false);
    this.addConnector(connector);
    File webapp = new File(Configurations.get("refine.webapp", "main/webapp"));
    if (!isWebapp(webapp)) {
        webapp = new File("main/webapp");
        if (!isWebapp(webapp)) {
            webapp = new File("webapp");
            if (!isWebapp(webapp)) {
                logger.warn("Warning: Failed to find web application at '" + webapp.getAbsolutePath() + "'");
                System.exit(-1);
            }
        }
    }
    final String contextPath = Configurations.get("refine.context_path", "/");
    final int maxFormContentSize = Configurations.getInteger("refine.max_form_content_size", 1048576);
    logger.info("Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");
    WebAppContext context = new WebAppContext(webapp.getAbsolutePath(), contextPath);
    context.setMaxFormContentSize(maxFormContentSize);
    this.setHandler(context);
    this.setStopAtShutdown(true);
    this.setSendServerVersion(true);
    // Enable context autoreloading
    if (Configurations.getBoolean("refine.autoreload", false)) {
        scanForUpdates(webapp, context);
    }
    // start the server
    try {
        this.start();
    } catch (BindException e) {
        logger.error("Failed to start server - is there another copy running already on this port/address?");
        throw e;
    }
    configure(context);
}
Also used : Connector(org.mortbay.jetty.Connector) SocketConnector(org.mortbay.jetty.bio.SocketConnector) ThreadPoolExecutorAdapter(com.google.util.threads.ThreadPoolExecutorAdapter) BindException(java.net.BindException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SocketConnector(org.mortbay.jetty.bio.SocketConnector) File(java.io.File)

Example 85 with LinkedBlockingQueue

use of java.util.concurrent.LinkedBlockingQueue in project azure-iot-sdk-java by Azure.

the class AmqpsTransportTest method handleMessagePutsMessageBackIntoQueueIfCannotSendResultBackToServer.

// Tests_SRS_AMQPSTRANSPORT_15_028: [If the result could not be sent to IoTHub, the message shall be put back in the received messages queue to be processed again.]
// Tests_SRS_AMQPSTRANSPORT_15_028: [If the result could not be sent to IoTHub, the message shall be put back in the received messages queue to be processed again.]
@Test
public void handleMessagePutsMessageBackIntoQueueIfCannotSendResultBackToServer() throws IOException {
    new NonStrictExpectations() {

        {
            new AmqpsIotHubConnection(mockConfig, false);
            result = mockConnection;
            mockConfig.getMessageCallback();
            result = mockMessageCallback;
            mockMessageCallback.execute((Message) any, any);
            result = IotHubMessageResult.COMPLETE;
            mockConnection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.COMPLETE);
            result = false;
        }
    };
    new MockUp<AmqpsTransport>() {

        @Mock
        Message protonMessageToIoTHubMessage(MessageImpl protonMessage) {
            return new Message();
        }
    };
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    Queue<AmqpsMessage> receivedMessages = new LinkedBlockingQueue<>();
    receivedMessages.add(mockAmqpsMessage);
    receivedMessages.add(mockAmqpsMessage);
    Deencapsulation.setField(transport, "receivedMessages", receivedMessages);
    transport.handleMessage();
    Queue<AmqpsMessage> receivedTransportMessages = Deencapsulation.getField(transport, "receivedMessages");
    Assert.assertTrue(receivedTransportMessages.size() == 2);
    new Verifications() {

        {
            mockMessageCallback.execute((Message) any, any);
            times = 1;
            mockConnection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.COMPLETE);
            times = 1;
        }
    };
    Assert.assertTrue(receivedTransportMessages.size() == 2);
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) Test(org.junit.Test)

Aggregations

LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)259 Test (org.junit.Test)91 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)64 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)23 Emitter (io.socket.emitter.Emitter)19 JSONObject (org.json.JSONObject)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 ThreadFactory (java.util.concurrent.ThreadFactory)16 ExecutorService (java.util.concurrent.ExecutorService)14 BlockingQueue (java.util.concurrent.BlockingQueue)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 List (java.util.List)12 URI (java.net.URI)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Intent (android.content.Intent)9 HashMap (java.util.HashMap)9 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)8 Map (java.util.Map)8 UUID (java.util.UUID)8