use of java.util.Observable in project android_frameworks_base by ResurrectionRemix.
the class ContentQueryMapTest method testContentQueryMap.
@MediumTest
public void testContentQueryMap() throws Throwable {
LooperThread thread = new LooperThread() {
void go() {
ContentResolver r = getContext().getContentResolver();
Settings.System.putString(r, "test", "Value");
Cursor cursor = r.query(Settings.System.CONTENT_URI, new String[] { Settings.System.NAME, Settings.System.VALUE }, null, null, null);
final ContentQueryMap cqm = new ContentQueryMap(cursor, Settings.System.NAME, true, null);
// Get the current state of the CQM. This forces a requery and means that the
// call to getValues() below won't do a requery().
cqm.getRows();
// The cache won't notice changes until the loop runs.
Settings.System.putString(r, "test", "New Value");
ContentValues v = cqm.getValues("test");
String value = v.getAsString(Settings.System.VALUE);
assertEquals("Value", value);
// Use an Observer to find out when the cache does update.
cqm.addObserver(new Observer() {
public void update(Observable o, Object arg) {
// Should have the new values by now.
ContentValues v = cqm.getValues("test");
String value = v.getAsString(Settings.System.VALUE);
assertEquals("New Value", value);
Looper.myLooper().quit();
cqm.close();
mSuccess = true;
}
});
// Give up after a few seconds, if it doesn't.
new Handler().postDelayed(new Runnable() {
public void run() {
fail("Timed out");
}
}, 5000);
}
};
thread.start();
thread.join();
if (thread.mError != null)
throw thread.mError;
assertTrue(thread.mSuccess);
}
use of java.util.Observable in project AutoRefactor by JnRouvignac.
the class SetRatherThanListSample method refactorWithMethod.
public boolean refactorWithMethod() {
// Keep this comment
java.util.HashSet<Observable> collection = new java.util.HashSet<Observable>();
// Keep this comment too
collection.add(new Observable());
return collection.contains(new Observable());
}
use of java.util.Observable in project felix by apache.
the class ServiceRegistryTest method testGetUngetServiceFactory.
public void testGetUngetServiceFactory() throws Exception {
final ServiceRegistry sr = new ServiceRegistry(null, null);
final Bundle regBundle = Mockito.mock(Bundle.class);
final ServiceRegistration<?> reg = sr.registerService(regBundle, new String[] { Observer.class.getName() }, new ServiceFactory<Observer>() {
final class ObserverImpl implements Observer {
private final AtomicInteger counter = new AtomicInteger();
public volatile boolean active = true;
@Override
public void update(Observable o, Object arg) {
counter.incrementAndGet();
if (!active) {
throw new IllegalArgumentException("Iteration:" + counter.get());
}
}
}
@Override
public Observer getService(Bundle bundle, ServiceRegistration<Observer> registration) {
return new ObserverImpl();
}
@Override
public void ungetService(Bundle bundle, ServiceRegistration<Observer> registration, Observer service) {
((ObserverImpl) service).active = false;
}
}, null);
final Bundle clientBundle = Mockito.mock(Bundle.class);
Mockito.when(clientBundle.getBundleId()).thenReturn(42L);
// check simple get/unget
final Object obj = sr.getService(clientBundle, reg.getReference(), false);
assertNotNull(obj);
assertTrue(obj instanceof Observer);
((Observer) obj).update(null, null);
sr.ungetService(clientBundle, reg.getReference(), null);
try {
((Observer) obj).update(null, null);
fail();
} catch (final IllegalArgumentException iae) {
// expected
}
// start three threads
final int MAX_THREADS = 3;
final int MAX_LOOPS = 50000;
final CountDownLatch latch = new CountDownLatch(MAX_THREADS);
final Thread[] threads = new Thread[MAX_THREADS];
final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
for (int i = 0; i < MAX_THREADS; i++) {
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.currentThread().sleep(50);
} catch (InterruptedException e1) {
// ignore
}
for (int i = 0; i < MAX_LOOPS; i++) {
try {
final Object obj = sr.getService(clientBundle, reg.getReference(), false);
((Observer) obj).update(null, null);
sr.ungetService(clientBundle, reg.getReference(), null);
} catch (final Exception e) {
exceptions.add(e);
}
}
latch.countDown();
}
});
}
for (int i = 0; i < MAX_THREADS; i++) {
threads[i].start();
}
latch.await();
List<String> counterValues = new ArrayList<String>();
for (Exception ex : exceptions) {
counterValues.add(ex.getMessage());
}
assertTrue("" + counterValues, exceptions.isEmpty());
}
use of java.util.Observable in project osumer by mob41.
the class Queue method start.
public void start() {
runBeforeActions();
setStartTime(System.nanoTime());
downloader.download();
downloader.deleteObservers();
downloader.addObserver(new Observer() {
@Override
public void update(Observable arg0, Object arg1) {
if (downloader.getStatus() == Downloader.COMPLETED) {
runAfterActions();
}
}
});
}
use of java.util.Observable in project opentest by mcdcorp.
the class SeleniumTestAction method initialize.
@Override
public void initialize() {
super.initialize();
if (!SeleniumTestAction.initialized) {
SeleniumTestAction.initialized = true;
SeleniumTestAction.config = SeleniumHelper.getConfig();
this.getActor().addObserver(new Observer() {
@Override
public void update(Observable eventSource, Object eventData) {
if (eventSource instanceof ITestActor) {
if (eventData == TestActorEvents.TEST_COMPLETED) {
SeleniumTestAction.discardActionsObject();
if (!SeleniumHelper.getConfig().getBoolean("selenium.reuseDriver", false)) {
SeleniumHelper.discardDriver();
}
}
}
}
});
}
this.explicitWaitSec = this.readIntArgument("explicitWaitSec", SeleniumHelper.getExplicitWaitSec());
this.driver = SeleniumHelper.getDriver();
}
Aggregations