Search in sources :

Example 41 with TimeoutException

use of org.apache.geode.cache.TimeoutException in project geode by apache.

the class SearchAndLoadDUnitTest method testNetWrite.

@Test
public void testNetWrite() throws CacheException, InterruptedException {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final String name = this.getUniqueName() + "-ACK";
    final String objectName = "Gemfire7";
    final Integer value = new Integer(483);
    vm0.invoke(new SerializableRunnable("Create ACK Region with cacheWriter") {

        public void run() {
            netWriteInvoked = false;
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setCacheWriter(new CacheWriter() {

                    public void beforeCreate(EntryEvent e) throws CacheWriterException {
                        netWriteInvoked = true;
                        return;
                    }

                    public void beforeUpdate(EntryEvent e) throws CacheWriterException {
                        netWriteInvoked = true;
                        return;
                    }

                    public void beforeDestroy(EntryEvent e) throws CacheWriterException {
                        return;
                    }

                    public void beforeRegionDestroy(RegionEvent e) throws CacheWriterException {
                        return;
                    }

                    public void beforeRegionClear(RegionEvent e) throws CacheWriterException {
                        return;
                    }

                    public void close() {
                    }
                });
                createRegion(name, factory.create());
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Create ACK Region") {

        public void run() {
            loaderInvoked = false;
            remoteLoaderInvoked = false;
            netWriteInvoked = false;
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                createRegion(name, factory.create());
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Do a put operation resulting in cache writer notification in other vm") {

        public void run() {
            try {
                getRootRegion().getSubregion(name).put(objectName, value);
                try {
                    Object result = getRootRegion().getSubregion(name).get(objectName);
                    assertEquals(result, value);
                } catch (CacheLoaderException cle) {
                } catch (TimeoutException te) {
                }
            } catch (CacheWriterException cwe) {
            } catch (TimeoutException te) {
            }
        }
    });
    vm0.invoke(new SerializableRunnable("ensure that cache writer was invoked") {

        public void run() {
            assertTrue("expected cache writer to be invoked", netWriteInvoked);
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RegionEvent(org.apache.geode.cache.RegionEvent) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) VM(org.apache.geode.test.dunit.VM) CacheWriter(org.apache.geode.cache.CacheWriter) EntryEvent(org.apache.geode.cache.EntryEvent) TimeoutException(org.apache.geode.cache.TimeoutException) CacheWriterException(org.apache.geode.cache.CacheWriterException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 42 with TimeoutException

use of org.apache.geode.cache.TimeoutException in project geode by apache.

the class SearchAndLoadDUnitTest method testNetLoadNoLoaders.

@Test
public void testNetLoadNoLoaders() throws CacheException, InterruptedException {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final String name = this.getUniqueName() + "-ACK";
    final String objectName = "B";
    SerializableRunnable create = new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setEarlyAck(false);
            createRegion(name, factory.create());
        }
    };
    vm0.invoke(create);
    vm1.invoke(create);
    vm0.invoke(new SerializableRunnable("Get with No Loaders defined") {

        public void run() {
            try {
                Object result = getRootRegion().getSubregion(name).get(objectName);
                assertNull(result);
            } catch (CacheLoaderException cle) {
                Assert.fail("While getting value for ACK region", cle);
            } catch (TimeoutException te) {
                Assert.fail("While getting value for ACK region", te);
            }
        }
    });
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 43 with TimeoutException

use of org.apache.geode.cache.TimeoutException in project geode by apache.

the class LocalRegion method evictDestroy.

/**
   * @return true if the evict destroy was done; false if it was not needed
   */
boolean evictDestroy(LRUEntry entry) {
    checkReadiness();
    @Released final EntryEventImpl event = generateEvictDestroyEvent(entry.getKey());
    try {
        return mapDestroy(// cacheWrite
        event, // cacheWrite
        false, // isEviction
        true, // expectedOldValue
        null);
    } catch (CacheWriterException error) {
        throw new Error(LocalizedStrings.LocalRegion_CACHE_WRITER_SHOULD_NOT_HAVE_BEEN_CALLED_FOR_EVICTDESTROY.toLocalizedString(), error);
    } catch (TimeoutException anotherError) {
        throw new Error(LocalizedStrings.LocalRegion_NO_DISTRIBUTED_LOCK_SHOULD_HAVE_BEEN_ATTEMPTED_FOR_EVICTDESTROY.toLocalizedString(), anotherError);
    } catch (EntryNotFoundException yetAnotherError) {
        throw new Error(LocalizedStrings.LocalRegion_ENTRYNOTFOUNDEXCEPTION_SHOULD_BE_MASKED_FOR_EVICTDESTROY.toLocalizedString(), yetAnotherError);
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireError(org.apache.geode.InternalGemFireError) CacheWriterException(org.apache.geode.cache.CacheWriterException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 44 with TimeoutException

use of org.apache.geode.cache.TimeoutException in project geode by apache.

the class LocalRegion method localDestroyRegion.

@Override
public void localDestroyRegion(Object aCallbackArgument) {
    getDataView().checkSupportsRegionDestroy();
    RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_LOCAL_DESTROY, aCallbackArgument, false, getMyId(), generateEventID());
    try {
        basicDestroyRegion(event, false);
    } catch (CacheWriterException e) {
        // not possible with local operation, CacheWriter not called
        throw new Error(LocalizedStrings.LocalRegion_CACHEWRITEREXCEPTION_SHOULD_NOT_BE_THROWN_IN_LOCALDESTROYREGION.toLocalizedString(), e);
    } catch (TimeoutException e) {
        // not possible with local operation, no distributed locks possible
        throw new Error(LocalizedStrings.LocalRegion_TIMEOUTEXCEPTION_SHOULD_NOT_BE_THROWN_IN_LOCALDESTROYREGION.toLocalizedString(), e);
    }
}
Also used : InternalGemFireError(org.apache.geode.InternalGemFireError) CacheWriterException(org.apache.geode.cache.CacheWriterException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 45 with TimeoutException

use of org.apache.geode.cache.TimeoutException in project geode by apache.

the class LocalManager method startLocalManagement.

/**
   * Managed Node side resources are created
   * 
   * Management Region : its a Replicated NO_ACK region Notification Region : its a Replicated Proxy
   * NO_ACK region
   */
private void startLocalManagement(Map<ObjectName, FederationComponent> federatedComponentMap) {
    synchronized (this) {
        if (repo.getLocalMonitoringRegion() != null) {
            return;
        } else {
            ThreadFactory tf = new ThreadFactory() {

                public Thread newThread(final Runnable command) {
                    final Runnable r = new Runnable() {

                        public void run() {
                            command.run();
                        }
                    };
                    final ThreadGroup group = LoggingThreadGroup.createThreadGroup(ManagementStrings.MANAGEMENT_TASK_THREAD_GROUP.toLocalizedString(), logger);
                    Thread thread = new Thread(group, r, ManagementStrings.MANAGEMENT_TASK.toLocalizedString());
                    thread.setDaemon(true);
                    return thread;
                }
            };
            singleThreadFederationScheduler = Executors.newSingleThreadScheduledExecutor(tf);
            if (logger.isDebugEnabled()) {
                logger.debug("Creating  Management Region :");
            }
            /*
         * Sharing the same Internal Argument for both notification region and monitoring region
         */
            InternalRegionArguments internalArgs = new InternalRegionArguments();
            internalArgs.setIsUsedForMetaRegion(true);
            // Create anonymous stats holder for Management Regions
            final HasCachePerfStats monitoringRegionStats = new HasCachePerfStats() {

                public CachePerfStats getCachePerfStats() {
                    return new CachePerfStats(cache.getDistributedSystem(), "managementRegionStats");
                }
            };
            internalArgs.setCachePerfStatsHolder(monitoringRegionStats);
            AttributesFactory<String, Object> monitorRegionAttributeFactory = new AttributesFactory<String, Object>();
            monitorRegionAttributeFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
            monitorRegionAttributeFactory.setDataPolicy(DataPolicy.REPLICATE);
            monitorRegionAttributeFactory.setConcurrencyChecksEnabled(false);
            MonitoringRegionCacheListener localListener = new MonitoringRegionCacheListener(service);
            monitorRegionAttributeFactory.addCacheListener(localListener);
            RegionAttributes<String, Object> monitoringRegionAttrs = monitorRegionAttributeFactory.create();
            AttributesFactory<NotificationKey, Notification> notificationRegionAttributeFactory = new AttributesFactory<NotificationKey, Notification>();
            notificationRegionAttributeFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
            notificationRegionAttributeFactory.setDataPolicy(DataPolicy.EMPTY);
            notificationRegionAttributeFactory.setConcurrencyChecksEnabled(false);
            RegionAttributes<NotificationKey, Notification> notifRegionAttrs = notificationRegionAttributeFactory.create();
            String appender = MBeanJMXAdapter.getUniqueIDForMember(cache.getDistributedSystem().getDistributedMember());
            boolean monitoringRegionCreated = false;
            boolean notifRegionCreated = false;
            try {
                repo.setLocalMonitoringRegion(cache.createVMRegion(ManagementConstants.MONITORING_REGION + "_" + appender, monitoringRegionAttrs, internalArgs));
                monitoringRegionCreated = true;
            } catch (TimeoutException e) {
                throw new ManagementException(e);
            } catch (RegionExistsException e) {
                throw new ManagementException(e);
            } catch (IOException e) {
                throw new ManagementException(e);
            } catch (ClassNotFoundException e) {
                throw new ManagementException(e);
            }
            try {
                repo.setLocalNotificationRegion(cache.createVMRegion(ManagementConstants.NOTIFICATION_REGION + "_" + appender, notifRegionAttrs, internalArgs));
                notifRegionCreated = true;
            } catch (TimeoutException e) {
                throw new ManagementException(e);
            } catch (RegionExistsException e) {
                throw new ManagementException(e);
            } catch (IOException e) {
                throw new ManagementException(e);
            } catch (ClassNotFoundException e) {
                throw new ManagementException(e);
            } finally {
                if (!notifRegionCreated && monitoringRegionCreated) {
                    repo.getLocalMonitoringRegion().localDestroyRegion();
                }
            }
            managementTask = new ManagementTask(federatedComponentMap);
            // call run to get us initialized immediately with a sync call
            managementTask.run();
            // All local resources are created for the ManagementTask
            // Now Management tasks can proceed.
            int updateRate = cache.getInternalDistributedSystem().getConfig().getJmxManagerUpdateRate();
            singleThreadFederationScheduler.scheduleAtFixedRate(managementTask, updateRate, updateRate, TimeUnit.MILLISECONDS);
            if (logger.isDebugEnabled()) {
                logger.debug("Management Region created with Name : {}", repo.getLocalMonitoringRegion().getName());
                logger.debug("Notification Region created with Name : {}", repo.getLocalNotificationRegion().getName());
            }
        }
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) RegionExistsException(org.apache.geode.cache.RegionExistsException) Notification(javax.management.Notification) ManagementException(org.apache.geode.management.ManagementException) AttributesFactory(org.apache.geode.cache.AttributesFactory) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) LoggingThreadGroup(org.apache.geode.internal.logging.LoggingThreadGroup) TimeoutException(org.apache.geode.cache.TimeoutException) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) IOException(java.io.IOException)

Aggregations

TimeoutException (org.apache.geode.cache.TimeoutException)48 Test (org.junit.Test)24 CacheException (org.apache.geode.cache.CacheException)22 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)21 Host (org.apache.geode.test.dunit.Host)20 VM (org.apache.geode.test.dunit.VM)20 Region (org.apache.geode.cache.Region)18 AttributesFactory (org.apache.geode.cache.AttributesFactory)17 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)14 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)13 CacheWriterException (org.apache.geode.cache.CacheWriterException)10 LoaderHelper (org.apache.geode.cache.LoaderHelper)10 Lock (java.util.concurrent.locks.Lock)8 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)6 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 DLockTest (org.apache.geode.test.junit.categories.DLockTest)6 IOException (java.io.IOException)5 InternalGemFireError (org.apache.geode.InternalGemFireError)5 CacheWriter (org.apache.geode.cache.CacheWriter)5 StringId (org.apache.geode.i18n.StringId)5