Search in sources :

Example 6 with SimpleImmutableEntry

use of java.util.AbstractMap.SimpleImmutableEntry in project buck by facebook.

the class AppleSimulatorControllerTest method cannotStartSimulatorWhenSimulatorWithDifferentUdidExists.

@Test
public void cannotStartSimulatorWhenSimulatorWithDifferentUdidExists() throws IOException, InterruptedException {
    ImmutableList.Builder<Map.Entry<ProcessExecutorParams, FakeProcess>> fakeProcessesBuilder = ImmutableList.builder();
    fakeProcessesBuilder.add(new SimpleImmutableEntry<>(SIMCTL_LIST_PARAMS, new FakeProcess(0, "    iPhone 5 (45BD7164-686C-474F-8C68-3730432BC5F2) (Booted)\n" + "    iPhone 5s (70200ED8-EEF1-4BDB-BCCF-3595B137D67D) (Shutdown)\n", "")));
    FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(fakeProcessesBuilder.build());
    AppleSimulatorController appleSimulatorController = new AppleSimulatorController(fakeProcessExecutor, SIMCTL_PATH, IOS_SIMULATOR_PATH);
    assertThat(appleSimulatorController.canStartSimulator("70200ED8-EEF1-4BDB-BCCF-3595B137D67D"), is(false));
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ImmutableList(com.google.common.collect.ImmutableList) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 7 with SimpleImmutableEntry

use of java.util.AbstractMap.SimpleImmutableEntry in project buck by facebook.

the class AppleSimulatorControllerTest method startingSimulatorWorksWhenSimulatorNotRunning.

@Test
public void startingSimulatorWorksWhenSimulatorNotRunning() throws IOException, InterruptedException {
    ImmutableList.Builder<Map.Entry<ProcessExecutorParams, FakeProcess>> fakeProcessesBuilder = ImmutableList.builder();
    fakeProcessesBuilder.add(new SimpleImmutableEntry<>(SIMCTL_LIST_PARAMS, new FakeProcess(0)));
    fakeProcessesBuilder.add(new SimpleImmutableEntry<>(ProcessExecutorParams.builder().setCommand(ImmutableList.of("open", "-a", IOS_SIMULATOR_PATH.toString(), "--args", "-CurrentDeviceUDID", "70200ED8-EEF1-4BDB-BCCF-3595B137D67D")).build(), new FakeProcess(0)));
    fakeProcessesBuilder.add(new SimpleImmutableEntry<>(SIMCTL_LIST_PARAMS, new FakeProcess(0, "    iPhone 5 (45BD7164-686C-474F-8C68-3730432BC5F2) (Shutdown)\n" + "    iPhone 5s (70200ED8-EEF1-4BDB-BCCF-3595B137D67D) (Booted)\n", "")));
    FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(fakeProcessesBuilder.build());
    AppleSimulatorController appleSimulatorController = new AppleSimulatorController(fakeProcessExecutor, SIMCTL_PATH, IOS_SIMULATOR_PATH);
    Optional<Long> result = appleSimulatorController.startSimulator("70200ED8-EEF1-4BDB-BCCF-3595B137D67D", 1000);
    assertThat(result, is(Optional.of(0L)));
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ImmutableList(com.google.common.collect.ImmutableList) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 8 with SimpleImmutableEntry

use of java.util.AbstractMap.SimpleImmutableEntry in project storio by pushtorefresh.

the class PreparedPutCollectionOfObjects method executeAsBlocking.

/**
     * Executes Put Operation immediately in current thread.
     * <p>
     * Notice: This is blocking I/O operation that should not be executed on the Main Thread,
     * it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
     * So please, call this method on some background thread. See {@link WorkerThread}.
     *
     * @return non-null result of Put Operation.
     */
@SuppressWarnings("unchecked")
@WorkerThread
@NonNull
@Override
public PutResults<T> executeAsBlocking() {
    try {
        final StorIOContentResolver.LowLevel lowLevel = storIOContentResolver.lowLevel();
        // Nullable
        final List<SimpleImmutableEntry<T, PutResolver<T>>> objectsAndPutResolvers;
        if (explicitPutResolver != null) {
            objectsAndPutResolvers = null;
        } else {
            objectsAndPutResolvers = new ArrayList<SimpleImmutableEntry<T, PutResolver<T>>>(objects.size());
            for (final T object : objects) {
                final ContentResolverTypeMapping<T> typeMapping = (ContentResolverTypeMapping<T>) lowLevel.typeMapping(object.getClass());
                if (typeMapping == null) {
                    throw new IllegalStateException("One of the objects from the collection does not have type mapping: " + "object = " + object + ", object.class = " + object.getClass() + "," + "ContentProvider was not affected by this operation, please add type mapping for this type");
                }
                objectsAndPutResolvers.add(new SimpleImmutableEntry<T, PutResolver<T>>(object, typeMapping.putResolver()));
            }
        }
        final Map<T, PutResult> results = new HashMap<T, PutResult>(objects.size());
        if (explicitPutResolver != null) {
            for (final T object : objects) {
                final PutResult putResult = explicitPutResolver.performPut(storIOContentResolver, object);
                results.put(object, putResult);
            }
        } else {
            for (final SimpleImmutableEntry<T, PutResolver<T>> objectAndPutResolver : objectsAndPutResolvers) {
                final T object = objectAndPutResolver.getKey();
                final PutResolver<T> putResolver = objectAndPutResolver.getValue();
                final PutResult putResult = putResolver.performPut(storIOContentResolver, object);
                results.put(object, putResult);
            }
        }
        return PutResults.newInstance(results);
    } catch (Exception exception) {
        throw new StorIOException("Error has occurred during Put operation. objects = " + objects, exception);
    }
}
Also used : HashMap(java.util.HashMap) ContentResolverTypeMapping(com.pushtorefresh.storio.contentresolver.ContentResolverTypeMapping) StorIOException(com.pushtorefresh.storio.StorIOException) StorIOException(com.pushtorefresh.storio.StorIOException) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 9 with SimpleImmutableEntry

use of java.util.AbstractMap.SimpleImmutableEntry in project storio by pushtorefresh.

the class PreparedDeleteCollectionOfObjects method executeAsBlocking.

/**
     * Executes Delete Operation immediately in current thread.
     * <p>
     * Notice: This is blocking I/O operation that should not be executed on the Main Thread,
     * it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
     * So please, call this method on some background thread. See {@link WorkerThread}.
     *
     * @return non-null results of Delete Operation.
     */
@SuppressWarnings("unchecked")
@WorkerThread
@NonNull
@Override
public DeleteResults<T> executeAsBlocking() {
    try {
        final StorIOContentResolver.LowLevel lowLevel = storIOContentResolver.lowLevel();
        // Nullable
        final List<SimpleImmutableEntry> objectsAndDeleteResolvers;
        if (explicitDeleteResolver != null) {
            objectsAndDeleteResolvers = null;
        } else {
            objectsAndDeleteResolvers = new ArrayList<SimpleImmutableEntry>(objects.size());
            for (final T object : objects) {
                final ContentResolverTypeMapping<T> typeMapping = (ContentResolverTypeMapping<T>) lowLevel.typeMapping(object.getClass());
                if (typeMapping == null) {
                    throw new IllegalStateException("One of the objects from the collection does not have type mapping: " + "object = " + object + ", object.class = " + object.getClass() + "," + "ContentProvider was not affected by this operation, please add type mapping for this type");
                }
                objectsAndDeleteResolvers.add(new SimpleImmutableEntry(object, typeMapping.deleteResolver()));
            }
        }
        final Map<T, DeleteResult> results = new HashMap<T, DeleteResult>(objects.size());
        if (explicitDeleteResolver != null) {
            for (final T object : objects) {
                final DeleteResult deleteResult = explicitDeleteResolver.performDelete(storIOContentResolver, object);
                results.put(object, deleteResult);
            }
        } else {
            for (final SimpleImmutableEntry<T, DeleteResolver<T>> objectAndDeleteResolver : objectsAndDeleteResolvers) {
                final T object = objectAndDeleteResolver.getKey();
                final DeleteResolver<T> deleteResolver = objectAndDeleteResolver.getValue();
                final DeleteResult deleteResult = deleteResolver.performDelete(storIOContentResolver, object);
                results.put(object, deleteResult);
            }
        }
        return DeleteResults.newInstance(results);
    } catch (Exception exception) {
        throw new StorIOException("Error has occurred during Delete operation. objects = " + objects, exception);
    }
}
Also used : HashMap(java.util.HashMap) ContentResolverTypeMapping(com.pushtorefresh.storio.contentresolver.ContentResolverTypeMapping) StorIOException(com.pushtorefresh.storio.StorIOException) StorIOException(com.pushtorefresh.storio.StorIOException) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 10 with SimpleImmutableEntry

use of java.util.AbstractMap.SimpleImmutableEntry in project storio by pushtorefresh.

the class PreparedPutCollectionOfObjects method executeAsBlocking.

/**
     * Executes Put Operation immediately in current thread.
     * <p>
     * Notice: This is blocking I/O operation that should not be executed on the Main Thread,
     * it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
     * So please, call this method on some background thread. See {@link WorkerThread}.
     *
     * @return non-null results of Put Operation.
     */
@SuppressWarnings("unchecked")
@WorkerThread
@NonNull
@Override
public PutResults<T> executeAsBlocking() {
    try {
        final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
        // Nullable
        final List<SimpleImmutableEntry<T, PutResolver<T>>> objectsAndPutResolvers;
        if (explicitPutResolver != null) {
            objectsAndPutResolvers = null;
        } else {
            objectsAndPutResolvers = new ArrayList<SimpleImmutableEntry<T, PutResolver<T>>>(objects.size());
            for (final T object : objects) {
                final SQLiteTypeMapping<T> typeMapping = (SQLiteTypeMapping<T>) lowLevel.typeMapping(object.getClass());
                if (typeMapping == null) {
                    throw new IllegalStateException("One of the objects from the collection does not have type mapping: " + "object = " + object + ", object.class = " + object.getClass() + "," + "db was not affected by this operation, please add type mapping for this type");
                }
                objectsAndPutResolvers.add(new SimpleImmutableEntry<T, PutResolver<T>>(object, typeMapping.putResolver()));
            }
        }
        if (useTransaction) {
            lowLevel.beginTransaction();
        }
        final Map<T, PutResult> results = new HashMap<T, PutResult>(objects.size());
        boolean transactionSuccessful = false;
        try {
            if (explicitPutResolver != null) {
                for (final T object : objects) {
                    final PutResult putResult = explicitPutResolver.performPut(storIOSQLite, object);
                    results.put(object, putResult);
                    if (!useTransaction && (putResult.wasInserted() || putResult.wasUpdated())) {
                        lowLevel.notifyAboutChanges(Changes.newInstance(putResult.affectedTables()));
                    }
                }
            } else {
                for (final SimpleImmutableEntry<T, PutResolver<T>> objectAndPutResolver : objectsAndPutResolvers) {
                    final T object = objectAndPutResolver.getKey();
                    final PutResolver<T> putResolver = objectAndPutResolver.getValue();
                    final PutResult putResult = putResolver.performPut(storIOSQLite, object);
                    results.put(object, putResult);
                    if (!useTransaction && (putResult.wasInserted() || putResult.wasUpdated())) {
                        lowLevel.notifyAboutChanges(Changes.newInstance(putResult.affectedTables()));
                    }
                }
            }
            if (useTransaction) {
                lowLevel.setTransactionSuccessful();
                transactionSuccessful = true;
            }
        } finally {
            if (useTransaction) {
                lowLevel.endTransaction();
                // if put was in transaction and it was successful -> notify about changes
                if (transactionSuccessful) {
                    // in most cases it will be 1 table
                    final Set<String> affectedTables = new HashSet<String>(1);
                    for (final T object : results.keySet()) {
                        final PutResult putResult = results.get(object);
                        if (putResult.wasInserted() || putResult.wasUpdated()) {
                            affectedTables.addAll(putResult.affectedTables());
                        }
                    }
                    // It'll reduce number of possible deadlock situations
                    if (!affectedTables.isEmpty()) {
                        lowLevel.notifyAboutChanges(Changes.newInstance(affectedTables));
                    }
                }
            }
        }
        return PutResults.newInstance(results);
    } catch (Exception exception) {
        throw new StorIOException("Error has occurred during Put operation. objects = " + objects, exception);
    }
}
Also used : HashMap(java.util.HashMap) StorIOException(com.pushtorefresh.storio.StorIOException) StorIOException(com.pushtorefresh.storio.StorIOException) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) SQLiteTypeMapping(com.pushtorefresh.storio.sqlite.SQLiteTypeMapping) HashSet(java.util.HashSet) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Aggregations

SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)29 Test (org.junit.Test)19 FakeProcess (com.facebook.buck.util.FakeProcess)9 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)9 ImmutableList (com.google.common.collect.ImmutableList)9 SortKey (javax.swing.RowSorter.SortKey)9 HashMap (java.util.HashMap)5 NonNull (android.support.annotation.NonNull)4 WorkerThread (android.support.annotation.WorkerThread)4 StorIOException (com.pushtorefresh.storio.StorIOException)4 Entry (java.util.Map.Entry)4 GeneratorState (com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)2 LabelState (com.github.anba.es6draft.compiler.CodeVisitor.LabelState)2 Completion (com.github.anba.es6draft.compiler.StatementGenerator.Completion)2 MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)2 ContentResolverTypeMapping (com.pushtorefresh.storio.contentresolver.ContentResolverTypeMapping)2 StorIOContentResolver (com.pushtorefresh.storio.contentresolver.StorIOContentResolver)2 SQLiteTypeMapping (com.pushtorefresh.storio.sqlite.SQLiteTypeMapping)2 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)2 ArrayList (java.util.ArrayList)2