Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: <T> void loadExistingIndexes(SpatialIndexCache<T> indexCache) throws java.io.IOException
        internal virtual void LoadExistingIndexes <T>(SpatialIndexCache <T> indexCache)
        {
            foreach (SpatialFile fileLayout in Existing())
            {
                indexCache.Select(fileLayout.Crs);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("Duplicates") @Test public void stressCache() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void StressCache()
        {
            StringFactory factory            = new StringFactory();
            SpatialIndexCache <string> cache = new SpatialIndexCache <string>(factory);

            ExecutorService pool = Executors.newFixedThreadPool(20);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?>[] futures = new java.util.concurrent.Future[100];
            Future <object>[] futures        = new Future[100];
            AtomicBoolean     shouldContinue = new AtomicBoolean(true);

            try
            {
                for (int i = 0; i < futures.Length; i++)
                {
                    futures[i] = pool.submit(new CacheStresser(cache, shouldContinue));
                }

                Thread.Sleep(5_000);

                shouldContinue.set(false);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.concurrent.Future<?> future : futures)
                foreach (Future <object> future in futures)
                {
                    future.get(10, TimeUnit.SECONDS);
                }
            }
            finally
            {
                pool.shutdown();
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void stressInstantiationWithClose() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void StressInstantiationWithClose()
        {
            // given
            StringFactory factory            = new StringFactory();
            SpatialIndexCache <string> cache = new SpatialIndexCache <string>(factory);
            Race       race = (new Race()).withRandomStartDelays();
            MutableInt instantiatedAtClose = new MutableInt();

            race.AddContestant(() =>
            {
                try
                {
                    cache.UncheckedSelect(CoordinateReferenceSystem.WGS84);
                    cache.UncheckedSelect(CoordinateReferenceSystem.Cartesian_3D);
                }
                catch (System.InvalidOperationException)
                {
                    // This exception is OK since it may have been closed
                }
            }, 1);
            race.AddContestant(() =>
            {
                cache.CloseInstantiateCloseLock();
                instantiatedAtClose.Value = count(cache);
            }, 1);

            // when
            race.Go();

            // then
            try
            {
                cache.UncheckedSelect(CoordinateReferenceSystem.Cartesian);
                fail("No instantiation after closed");
            }
            catch (System.InvalidOperationException)
            {
                // good
            }
            assertEquals(instantiatedAtClose.intValue(), count(cache));
        }
 internal CacheStresser(SpatialIndexCache <string> cache, AtomicBoolean shouldContinue)
 {
     this.Cache          = cache;
     this.ShouldContinue = shouldContinue;
 }