public TestQueueHolder() { // MutableClientServer Server = new MutableClientServer(new [] { "TestQueue2" }); IIgnite Ignite = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Mutable) ?? Ignition.GetIgnite(TRexGrids.MutableGridName()); QueueCache = Ignite.GetOrCreateCache <long, TestQueueItem>( new CacheConfiguration { Name = "TestQueueCache2", QueryEntities = new[] { new QueryEntity(typeof(long), typeof(TestQueueItem)) }, KeepBinaryInStore = true }); Add(DateTime.UtcNow, "First"); Add(DateTime.UtcNow, "Second"); Add(DateTime.UtcNow, "Third"); Add(DateTime.UtcNow, "Fourth"); Add(DateTime.UtcNow, "Fifth"); }
/// <summary> /// Gets the cache. /// </summary> protected static ICache <int, T> GetCache <T>() { return(Ignition.GetIgnite().GetOrCreateCache <int, T>(CacheName)); }
/// <summary> /// Gets the object store cache. /// </summary> private ICache <TK, TV> GetObjectStoreCache <TK, TV>() { return(Ignition.GetIgnite(GridName).GetCache <TK, TV>(ObjectStoreCacheName)); }
/// <summary> /// Gets the ignite. /// </summary> private static IIgnite GetIgnite() { return(Ignition.GetIgnite("grid-0")); }
/// <summary> /// Gets the template store cache. /// </summary> private ICache <int, string> GetTemplateStoreCache() { var cacheName = TemplateStoreCacheName.Replace("*", Guid.NewGuid().ToString()); return(Ignition.GetIgnite(GridName).GetOrCreateCache <int, string>(cacheName)); }
public void TestSession() { _dumps = new ConcurrentBag <ICollection <Operation> >(); var ignite = Ignition.GetIgnite(); var cache1 = ignite.GetCache <int, int>(Cache1); var cache2 = ignite.GetCache <int, int>(Cache2); // 1. Test rollback. using (var tx = ignite.GetTransactions().TxStart()) { cache1.Put(1, 1); cache2.Put(2, 2); tx.Rollback(); } // SessionEnd should not be called. Assert.AreEqual(0, _dumps.Count); // 2. Test puts. using (var tx = ignite.GetTransactions().TxStart()) { cache1.Put(1, 1); cache2.Put(2, 2); tx.Commit(); } Assert.AreEqual(StoreCount, _dumps.Count); foreach (var ops in _dumps) { Assert.AreEqual(2 + StoreCount, ops.Count); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Write && Cache1 == op.CacheName && 1 == op.Key && 1 == op.Value)); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Write && Cache2 == op.CacheName && 2 == op.Key && 2 == op.Value)); Assert.AreEqual(StoreCount, ops.Count(op => op.Type == OperationType.SesEnd && op.Commit)); } _dumps = new ConcurrentBag <ICollection <Operation> >(); // 3. Test removes. using (var tx = ignite.GetTransactions().TxStart()) { cache1.Remove(1); cache2.Remove(2); tx.Commit(); } Assert.AreEqual(StoreCount, _dumps.Count); foreach (var ops in _dumps) { Assert.AreEqual(2 + StoreCount, ops.Count); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Delete && Cache1 == op.CacheName && 1 == op.Key)); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Delete && Cache2 == op.CacheName && 2 == op.Key)); Assert.AreEqual(StoreCount, ops.Count(op => op.Type == OperationType.SesEnd && op.Commit)); } }
/// <summary> /// Gets the cache. /// </summary> private static ICache <int, CacheTestParallelLoadStore.Record> GetCache() { return(Ignition.GetIgnite().GetCache <int, CacheTestParallelLoadStore.Record>(ObjectStoreCacheName)); }
/// <summary> /// Executes the life cycle of the service until it is aborted /// </summary> public void Execute(IServiceContext context) { try { if (_log == null) { Console.WriteLine($"Error: Null logger present in {nameof(TAGFileBufferQueueService)}.{nameof(Execute)}"); } _log.LogInformation($"{nameof(TAGFileBufferQueueService)} {context.Name} starting executing"); _aborted = false; _waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); // Get the ignite grid and cache references var ignite = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Mutable) ?? Ignition.GetIgnite(TRexGrids.MutableGridName()); if (ignite == null) { _log.LogError("Ignite reference in service is null - aborting service execution"); return; } // Don't start operations until the local (mutable) grid is confirmed as active DIContext.ObtainRequired <IActivatePersistentGridServer>().WaitUntilGridActive(TRexGrids.MutableGridName()); // Once active, delay start of operations for a time to ensure everything is up and running var delay = DIContext.ObtainRequired <IConfigurationStore>().GetValueInt("TREX_TAG_FILE_BUFFER_QUEUE_SERVICE_OPERATION_START_DELAY_SECONDS", 120); _log.LogInformation($"Delaying start of operations for {delay} seconds"); Thread.Sleep(delay * 1000); _log.LogInformation("Obtaining queue cache reference"); var queueCache = ignite.GetCache <ITAGFileBufferQueueKey, TAGFileBufferQueueItem>(TRexCaches.TAGFileBufferQueueCacheName()); _handler = new TAGFileBufferQueueItemHandler(); while (_queryHandle == null && !_aborted) { try { // Construct the continuous query machinery // Set the initial query to return all elements in the cache // Instantiate the queryHandle and start the continuous query on the remote nodes // Note: Only cache items held on this local node will be handled here _log.LogInformation("Obtaining continuous query handle"); _queryHandle = queueCache.QueryContinuous (qry: new ContinuousQuery <ITAGFileBufferQueueKey, TAGFileBufferQueueItem>(new LocalTAGFileListener(_handler)) { Local = true }, initialQry: new ScanQuery <ITAGFileBufferQueueKey, TAGFileBufferQueueItem> { Local = true }); } catch (Exception e) { _log.LogError(e, "Exception while constructing continuous query, will sleep and retry"); Thread.Sleep(5000); } } if (_queryHandle == null || _aborted) { _log.LogInformation("No query handle available, or aborting"); return; } using (_queryHandle) { // Perform the initial query to grab all existing elements and add them to the grouper _log.LogInformation("Performing initial continuous query cursor scan of items"); _queryHandle.GetInitialQueryCursor().ForEach(item => _handler.Add(item.Key)); // Transition into steady state looking for new elements in the cache via the continuous query while (!_aborted) { try { // Cycle looking for new work to do as TAG files arrive until aborted... _log.LogInformation("Entering steady state continuous query scan of items to process in TAGFileBufferQueue"); do { _waitHandle.WaitOne(_serviceCheckIntervalMs); //Log.LogInformation("Continuous query scan of items to process in TAGFileBufferQueue still active"); } while (!_aborted); } catch (Exception e) { _log.LogError(e, "Tag file buffer service unhandled exception, waiting and trying again"); // Sleep for 5 seconds to see if things come right and then try again Thread.Sleep(5000); } } } _handler.Cancel(); } catch (Exception e) { _log.LogError(e, "Exception occurred performing initial set up of continuous query and scan of existing items"); } finally { _log.LogInformation($"{nameof(TAGFileBufferQueueService)} {context.Name} completed executing"); } }
private IIgnite GetGrid(int i) { return(Ignition.GetIgnite("grid-" + i)); }
/// <summary> /// No-arg constructor. Instantiates the continuous query and performs initial scan of elements that the remote filter /// will populate into the node-local groupers within the mutable grid. /// </summary> public TAGFileBufferQueueManager(bool runLocally) { _log.LogInformation("Establishing Ignite and TAG file buffer queue cache contexts"); // Get the ignite grid and cache references _ignite = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Mutable) ?? Ignition.GetIgnite(TRexGrids.MutableGridName()); var queueCache = _ignite.GetCache <ITAGFileBufferQueueKey, TAGFileBufferQueueItem>(TRexCaches.TAGFileBufferQueueCacheName()); var handler = new TAGFileBufferQueueItemHandler(); var tagFileFilter = new RemoteTAGFileFilter(handler); _log.LogInformation("Creating continuous query"); // Construct the continuous query machinery // Set the initial query to return all elements in the cache // Instantiate the queryHandle and start the continuous query on the remote nodes // Note: Only cache items held on this local node will be handled here _queryHandle = queueCache.QueryContinuous (qry: new ContinuousQuery <ITAGFileBufferQueueKey, TAGFileBufferQueueItem>(new LocalTAGFileListener(handler)) { Local = runLocally, Filter = tagFileFilter }, initialQry: new ScanQuery <ITAGFileBufferQueueKey, TAGFileBufferQueueItem> { Local = runLocally, Filter = tagFileFilter }); // Perform the initial query to grab all existing elements and add them to the grouper // All processing should happen on the remote node in the implementation of the TAGFileFilter remote filter foreach (var item in _queryHandle.GetInitialQueryCursor()) { _log.LogError( $"A cache entry ({item.Key}) from the TAG file buffer queue was passed back to the local scan query rather than intercepted by the remote filter"); } _log.LogInformation("Completed TAG file buffer queue manager initialization"); }
public void TestStartGetStop() { var cfgs = new List <string> { "config\\start-test-grid1.xml", "config\\start-test-grid2.xml", "config\\start-test-grid3.xml" }; var cfg = new IgniteConfiguration { SpringConfigUrl = cfgs[0], JvmOptions = TestUtils.TestJavaOptions(), JvmClasspath = TestUtils.CreateTestClasspath() }; var grid1 = Ignition.Start(cfg); Assert.AreEqual("grid1", grid1.Name); cfg.SpringConfigUrl = cfgs[1]; var grid2 = Ignition.Start(cfg); Assert.AreEqual("grid2", grid2.Name); cfg.SpringConfigUrl = cfgs[2]; var grid3 = Ignition.Start(cfg); Assert.IsNull(grid3.Name); Assert.AreSame(grid1, Ignition.GetIgnite("grid1")); Assert.AreSame(grid2, Ignition.GetIgnite("grid2")); Assert.AreSame(grid3, Ignition.GetIgnite(null)); try { Ignition.GetIgnite("invalid_name"); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } Assert.IsTrue(Ignition.Stop("grid1", true)); try { Ignition.GetIgnite("grid1"); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } grid2.Dispose(); try { Ignition.GetIgnite("grid2"); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } grid3.Dispose(); try { Ignition.GetIgnite(null); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } foreach (var cfgName in cfgs) { cfg.SpringConfigUrl = cfgName; cfg.JvmOptions = TestUtils.TestJavaOptions(); Ignition.Start(cfg); } foreach (var gridName in new List <string> { "grid1", "grid2", null }) { Assert.IsNotNull(Ignition.GetIgnite(gridName)); } Ignition.StopAll(true); foreach (var gridName in new List <string> { "grid1", "grid2", null }) { try { Ignition.GetIgnite(gridName); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } } }
/// <summary> /// Returns Ignite cluster. /// </summary> private ICluster GetCluster() { return(Ignition.GetIgnite().GetCluster()); }
public MyDbConfiguration() : base(Ignition.GetIgnite(), null, null, Policy) { // No-op. }
/// <summary> /// Executes the life cycle of the service until it is aborted /// </summary> public void Execute(IServiceContext context) { try { if (_log == null) { Console.WriteLine($"Error: Null logger present in {nameof(SiteModelChangeProcessorService)}.{nameof(Execute)}"); } _log.LogInformation($"{context.Name} starting executing"); Aborted = false; _waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); // Get the ignite grid and cache references var ignite = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Immutable) ?? Ignition.GetIgnite(TRexGrids.ImmutableGridName()); if (ignite == null) { _log.LogError("Ignite reference in service is null - aborting service execution"); return; } // Don't start operations until the local (immutable) grid is confirmed as active DIContext.ObtainRequired <IActivatePersistentGridServer>().WaitUntilGridActive(TRexGrids.ImmutableGridName()); // Once active, delay start of operations for a time to ensure everything is up and running var delay = DIContext.ObtainRequired <IConfigurationStore>().GetValueInt("TREX_SITE_MODEL_CHANGE_MAP_SERVICE_OPERATION_START_DELAY_SECONDS", 120); _log.LogInformation($"Delaying start of operations for {delay} seconds"); Thread.Sleep(delay * 1000); _log.LogInformation("Obtaining queue cache reference"); var queueCache = ignite.GetCache <ISiteModelChangeBufferQueueKey, ISiteModelChangeBufferQueueItem>(TRexCaches.SiteModelChangeBufferQueueCacheName()); _log.LogInformation($"Obtained queue cache for SiteModelChangeBufferQueueKey: {queueCache}"); var handler = new SiteModelChangeProcessorItemHandler(); var listener = new LocalSiteModelChangeListener(handler); // Obtain the query handle for the continuous query from the DI context, or if not available create it directly // Construct the continuous query machinery // Set the initial query to return all elements in the cache // Instantiate the queryHandle and start the continuous query on the remote nodes // Note: Only cache items held on this local node will be handled here var queryHandleFactory = DIContext.Obtain <Func <LocalSiteModelChangeListener, IContinuousQueryHandle <ICacheEntry <ISiteModelChangeBufferQueueKey, ISiteModelChangeBufferQueueItem> > > >(); if (queryHandleFactory != null) { _log.LogInformation("Obtaining query handle from DI factory"); _queryHandle = queryHandleFactory(listener); } while (_queryHandle == null && !Aborted) { _log.LogInformation("Obtaining query handle from QueryContinuous() API"); try { _queryHandle = queueCache.QueryContinuous (qry: new ContinuousQuery <ISiteModelChangeBufferQueueKey, ISiteModelChangeBufferQueueItem>(listener) { Local = true }, initialQry: new ScanQuery <ISiteModelChangeBufferQueueKey, ISiteModelChangeBufferQueueItem> { Local = true }); } catch (Exception e) { _log.LogError(e, "Exception while constructing continuous query, will sleep and retry"); Thread.Sleep(5000); } } if (_queryHandle == null || Aborted) { _log.LogInformation("No query handle available, or aborting"); return; } using (_queryHandle) { _log.LogInformation("Performing initial continuous query cursor scan of items to process"); // Perform the initial query to grab all existing elements and process them. Make sure to sort them in time order first _queryHandle.GetInitialQueryCursor().OrderBy(x => x.Key.InsertUTCTicks).ForEach(handler.Add); while (!Aborted) { try { { // Cycle looking for new work to do as items arrive until aborted... _log.LogInformation("Entering steady state continuous query scan of items to process"); // Activate the handler with the inject initial continuous query and move into steady state processing InSteadyState = true; handler.Activate(); do { _waitHandle.WaitOne(_serviceCheckIntervalMs); } while (!Aborted); } } catch (Exception e) { _log.LogError(e, "Site model change processor service unhandled exception, waiting and trying again"); // Sleep for 5 seconds to see if things come right and then try again Thread.Sleep(5000); } } } handler.Cancel(); } catch (Exception e) { _log.LogError(e, "Exception occurred performing initial set up of continuous query and scan of existing items"); } finally { _log.LogInformation($"{context.Name} completed executing"); } }
public void TestStartGetStop() { var cfgs = new List <string> { "config\\start-test-grid1.xml", "config\\start-test-grid2.xml", "config\\start-test-grid3.xml" }; var cfg = new IgniteConfiguration { SpringConfigUrl = cfgs[0], JvmOptions = TestUtils.TestJavaOptions(), JvmClasspath = TestUtils.CreateTestClasspath() }; var grid1 = Ignition.Start(cfg); Assert.AreEqual("grid1", grid1.Name); Assert.AreSame(grid1, Ignition.GetIgnite()); Assert.AreSame(grid1, Ignition.GetAll().Single()); cfg.SpringConfigUrl = cfgs[1]; var grid2 = Ignition.Start(cfg); Assert.AreEqual("grid2", grid2.Name); Assert.Throws <IgniteException>(() => Ignition.GetIgnite()); cfg.SpringConfigUrl = cfgs[2]; var grid3 = Ignition.Start(cfg); Assert.IsNull(grid3.Name); Assert.AreSame(grid1, Ignition.GetIgnite("grid1")); Assert.AreSame(grid1, Ignition.TryGetIgnite("grid1")); Assert.AreSame(grid2, Ignition.GetIgnite("grid2")); Assert.AreSame(grid2, Ignition.TryGetIgnite("grid2")); Assert.AreSame(grid3, Ignition.GetIgnite(null)); Assert.AreSame(grid3, Ignition.GetIgnite()); Assert.AreSame(grid3, Ignition.TryGetIgnite(null)); Assert.AreSame(grid3, Ignition.TryGetIgnite()); Assert.AreEqual(new[] { grid3, grid1, grid2 }, Ignition.GetAll().OrderBy(x => x.Name).ToArray()); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("invalid_name")); Assert.IsNull(Ignition.TryGetIgnite("invalid_name")); Assert.IsTrue(Ignition.Stop("grid1", true)); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid1")); grid2.Dispose(); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid2")); grid3.Dispose(); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid3")); foreach (var cfgName in cfgs) { cfg.SpringConfigUrl = cfgName; cfg.JvmOptions = TestUtils.TestJavaOptions(); Ignition.Start(cfg); } foreach (var gridName in new List <string> { "grid1", "grid2", null }) { Assert.IsNotNull(Ignition.GetIgnite(gridName)); } Ignition.StopAll(true); foreach (var gridName in new List <string> { "grid1", "grid2", null }) { Assert.Throws <IgniteException>(() => Ignition.GetIgnite(gridName)); } }
public void TestAddRemoveFieldsDynamically() { var cache1 = Ignition.GetIgnite().GetOrCreateCache <int, DynamicFieldSetSerializable>("c").AsCacheClient(); var cache2 = Client.GetCache <int, DynamicFieldSetSerializable>("c"); if (_clientToServer) { // Swap caches to verify that metadata propagates both ways. var tmp = cache1; cache1 = cache2; cache2 = tmp; } // Put/get without optional fields. var noFields = new DynamicFieldSetSerializable(); cache1[1] = noFields; AssertExtensions.ReflectionEqual(noFields, cache1[1]); AssertExtensions.ReflectionEqual(noFields, cache2[1]); Assert.AreEqual(new[] { "WriteBar", "WriteFoo" }, GetFieldsServer()); Assert.AreEqual(new[] { "WriteBar", "WriteFoo" }, GetFieldsClient()); // Put/get with one optional field. var oneField = new DynamicFieldSetSerializable { Bar = "abc", WriteBar = true }; cache1[2] = oneField; AssertExtensions.ReflectionEqual(oneField, cache1[2]); AssertExtensions.ReflectionEqual(oneField, cache2[2]); Assert.AreEqual(new[] { "Bar", "WriteBar", "WriteFoo" }, GetFieldsServer()); Assert.AreEqual(new[] { "Bar", "WriteBar", "WriteFoo" }, GetFieldsClient()); // Put/get with another optional field. var oneField2 = new DynamicFieldSetSerializable { Foo = 25, WriteFoo = true }; cache1[3] = oneField2; AssertExtensions.ReflectionEqual(oneField2, cache1[3]); AssertExtensions.ReflectionEqual(oneField2, cache2[3]); Assert.AreEqual(new[] { "Bar", "Foo", "WriteBar", "WriteFoo" }, GetFieldsServer()); Assert.AreEqual(new[] { "Bar", "Foo", "WriteBar", "WriteFoo" }, GetFieldsClient()); // Put/get with both optional fields. var twoField = new DynamicFieldSetSerializable { Bar = "x", Foo = 42, WriteBar = true, WriteFoo = true }; cache1[4] = twoField; AssertExtensions.ReflectionEqual(twoField, cache1[4]); AssertExtensions.ReflectionEqual(twoField, cache2[4]); // Re-check initial object without optional fields. AssertExtensions.ReflectionEqual(noFields, cache1[1]); AssertExtensions.ReflectionEqual(noFields, cache2[1]); }
public void TestRemoveAll() { // Use new cache to avoid touching static data. var cache = Ignition.GetIgnite().CreateCache <int, Person>(new CacheConfiguration("deleteAllTest", new QueryEntity(typeof(int), typeof(Person))) { SqlEscapeAll = GetSqlEscapeAll() }); Enumerable.Range(1, 10).ToList().ForEach(x => cache.Put(x, new Person(x, x.ToString()))); var queryable = cache.AsCacheQueryable(); Func <int[]> getKeys = () => cache.Select(x => x.Key).OrderBy(x => x).ToArray(); // Without predicate. var res = queryable.Where(x => x.Key < 3).RemoveAll(); Assert.AreEqual(2, res); Assert.AreEqual(Enumerable.Range(3, 8), getKeys()); // With predicate. res = queryable.RemoveAll(x => x.Key < 7); Assert.AreEqual(4, res); Assert.AreEqual(Enumerable.Range(7, 4), getKeys()); // Subquery-style join. var ids = GetPersonCache().AsCacheQueryable().Where(x => x.Key == 7).Select(x => x.Key); res = queryable.Where(x => ids.Contains(x.Key)).RemoveAll(); Assert.AreEqual(1, res); Assert.AreEqual(Enumerable.Range(8, 3), getKeys()); // Row number limit. res = queryable.Take(2).RemoveAll(); Assert.AreEqual(2, res); Assert.AreEqual(1, getKeys().Length); // Unconditional. queryable.RemoveAll(); Assert.AreEqual(0, cache.GetSize()); // Skip is not supported with DELETE. var nex = Assert.Throws <NotSupportedException>(() => queryable.Skip(1).RemoveAll()); Assert.AreEqual( "RemoveAll can not be combined with result operators (other than Take): SkipResultOperator", nex.Message); // Multiple result operators are not supported with DELETE. nex = Assert.Throws <NotSupportedException>(() => queryable.Skip(1).Take(1).RemoveAll()); Assert.AreEqual( "RemoveAll can not be combined with result operators (other than Take): SkipResultOperator, " + "TakeResultOperator, RemoveAllResultOperator", nex.Message); // Joins are not supported in H2. var qry = queryable .Where(x => x.Key == 7) .Join(GetPersonCache().AsCacheQueryable(), p => p.Key, p => p.Key, (p1, p2) => p1); var ex = Assert.Throws <IgniteException>(() => qry.RemoveAll()); Assert.AreEqual("Failed to parse query", ex.Message.Substring(0, 21)); }
public void Invoke() { Console.WriteLine("Hello node: " + Ignition.GetIgnite().GetCluster().GetLocalNode().Id); }
public void TestJavaServiceCall() { var serviceName = TestUtils.DeployJavaService(Ignition.GetIgnite()); var svc = Client.GetServices().GetServiceProxy <IJavaService>(serviceName); var binSvc = Client.GetServices() .WithKeepBinary() .WithServerKeepBinary() .GetServiceProxy <IJavaService>(serviceName); Assert.IsTrue(svc.isInitialized()); Assert.IsTrue(svc.isExecuted()); Assert.IsFalse(svc.isCancelled()); // Primitives. Assert.AreEqual(4, svc.test((byte)3)); Assert.AreEqual(5, svc.test((short)4)); Assert.AreEqual(6, svc.test(5)); Assert.AreEqual(6, svc.test((long)5)); Assert.AreEqual(3.8f, svc.test(2.3f)); Assert.AreEqual(5.8, svc.test(3.3)); Assert.IsFalse(svc.test(true)); Assert.AreEqual('b', svc.test('a')); Assert.AreEqual("Foo!", svc.test("Foo")); // Nullables (Java wrapper types). Assert.AreEqual(4, svc.testWrapper(3)); Assert.AreEqual(5, svc.testWrapper((short?)4)); Assert.AreEqual(6, svc.testWrapper((int?)5)); Assert.AreEqual(6, svc.testWrapper((long?)5)); Assert.AreEqual(3.8f, svc.testWrapper(2.3f)); Assert.AreEqual(5.8, svc.testWrapper(3.3)); Assert.AreEqual(false, svc.testWrapper(true)); Assert.AreEqual('b', svc.testWrapper('a')); // Arrays. Assert.AreEqual(new byte[] { 2, 3, 4 }, svc.testArray(new byte[] { 1, 2, 3 })); Assert.AreEqual(new short[] { 2, 3, 4 }, svc.testArray(new short[] { 1, 2, 3 })); Assert.AreEqual(new[] { 2, 3, 4 }, svc.testArray(new[] { 1, 2, 3 })); Assert.AreEqual(new long[] { 2, 3, 4 }, svc.testArray(new long[] { 1, 2, 3 })); Assert.AreEqual(new float[] { 2, 3, 4 }, svc.testArray(new float[] { 1, 2, 3 })); Assert.AreEqual(new double[] { 2, 3, 4 }, svc.testArray(new double[] { 1, 2, 3 })); Assert.AreEqual(new[] { "a1", "b1" }, svc.testArray(new [] { "a", "b" })); Assert.AreEqual(new[] { 'c', 'd' }, svc.testArray(new[] { 'b', 'c' })); Assert.AreEqual(new[] { false, true, false }, svc.testArray(new[] { true, false, true })); // Nulls. Assert.AreEqual(9, svc.testNull(8)); Assert.IsNull(svc.testNull(null)); // params / varargs. Assert.AreEqual(5, svc.testParams(1, 2, 3, 4, "5")); Assert.AreEqual(0, svc.testParams()); // Overloads. Assert.AreEqual(3, svc.test(2, "1")); Assert.AreEqual(3, svc.test("1", 2)); // Dates & Timestamps: not supported in Thin Client Services. var ex = Assert.Throws <IgniteClientException>(() => svc.test(DateTime.UtcNow)); StringAssert.StartsWith("Failed to resolve .NET class 'System.DateTime' in Java", ex.Message); // Guid. var guid = Guid.NewGuid(); Assert.AreEqual(guid, svc.test(guid)); Assert.AreEqual(guid, svc.testNullUUID(guid)); Assert.IsNull(svc.testNullUUID(null)); Assert.AreEqual(guid, svc.testArray(new Guid?[] { guid })[0]); // Binary object. Assert.AreEqual(15, binSvc.testBinaryObject( Client.GetBinary().ToBinary <IBinaryObject>(new ServicesTest.PlatformComputeBinarizable { Field = 6 })) .GetField <int>("Field")); // Binary object array. var arr = new[] { 10, 11, 12 }.Select( x => new ServicesTest.PlatformComputeBinarizable { Field = x }).ToArray(); var binArr = arr.Select(Client.GetBinary().ToBinary <IBinaryObject>).ToArray(); Assert.AreEqual(new[] { 11, 12, 13 }, binSvc.testBinaryObjectArray(binArr) .Select(x => x.GetField <int>("Field"))); }
/// <summary> /// /// </summary> /// <param name="idx"></param> /// <returns></returns> public IIgnite GetIgnite(int idx) { return(Ignition.GetIgnite("grid-" + idx)); }
public void AfterTest() { var cache = Cache(); for (int i = 0; i < GridCnt; i++) { for (int j = 0; j < MaxItemCnt; j++) { cache.Remove(j); } Assert.IsTrue(cache.IsEmpty()); } TestUtils.AssertHandleRegistryIsEmpty(300, Enumerable.Range(0, GridCnt).Select(x => Ignition.GetIgnite("grid-" + x)).ToArray()); Console.WriteLine("Test finished: " + TestContext.CurrentContext.Test.Name); }
/// <summary> /// Checks the plugin target operations. /// </summary> private static void CheckPluginTarget(IPlatformTarget target, string expectedName, TestIgnitePluginProvider provider) { // Returns name. Assert.AreEqual(expectedName, target.OutStream(1, r => r.ReadString())); // Increments arg by one. Assert.AreEqual(3, target.InLongOutLong(1, 2)); Assert.AreEqual(5, target.InLongOutLong(1, 4)); // Returns string length. Assert.AreEqual(3, target.InStreamOutLong(1, w => w.WriteString("foo"))); Assert.AreEqual(6, target.InStreamOutLong(1, w => w.WriteString("foobar"))); // Returns uppercase string. Assert.AreEqual("FOO", target.InStreamOutStream(1, w => w.WriteString("foo"), r => r.ReadString())); Assert.AreEqual("BAR", target.InStreamOutStream(1, w => w.WriteString("bar"), r => r.ReadString())); // Returns target with specified name. var newTarget = target.InStreamOutObject(1, w => w.WriteString("name1")); Assert.AreEqual("name1", newTarget.OutStream(1, r => r.ReadString())); // Invokes callback to modify name, returns target with specified name appended. var res = target.InObjectStreamOutObjectStream(1, newTarget, w => w.WriteString("_abc"), (reader, t) => Tuple.Create(reader.ReadString(), t)); Assert.AreEqual("NAME1", res.Item1); // Old name converted by callback. Assert.AreEqual("name1_abc", res.Item2.OutStream(1, r => r.ReadString())); Assert.AreEqual("name1", provider.CallbackResult); // Old name. // Returns a copy with same name. var resCopy = res.Item2.OutObject(1); Assert.AreEqual("name1_abc", resCopy.OutStream(1, r => r.ReadString())); // Async operation. var task = target.DoOutOpAsync(1, w => w.WriteString("foo"), r => r.ReadString()); Assert.IsFalse(task.IsCompleted); var asyncRes = task.Result; Assert.IsTrue(task.IsCompleted); Assert.AreEqual("FOO", asyncRes); // Async operation with cancellation. var cts = new CancellationTokenSource(); task = target.DoOutOpAsync(1, w => w.WriteString("foo"), r => r.ReadString(), cts.Token); Assert.IsFalse(task.IsCompleted); cts.Cancel(); Assert.IsTrue(task.IsCanceled); var aex = Assert.Throws <AggregateException>(() => { asyncRes = task.Result; }); Assert.IsInstanceOf <TaskCanceledException>(aex.GetBaseException()); // Async operation with exception in entry point. Assert.Throws <TestIgnitePluginException>(() => target.DoOutOpAsync <object>(2, null, null)); // Async operation with exception in future. var errTask = target.DoOutOpAsync <object>(3, null, null); Assert.IsFalse(errTask.IsCompleted); aex = Assert.Throws <AggregateException>(() => errTask.Wait()); Assert.IsInstanceOf <IgniteException>(aex.InnerExceptions.Single()); // Throws custom mapped exception. var ex = Assert.Throws <TestIgnitePluginException>(() => target.InLongOutLong(-1, 0)); Assert.AreEqual("Baz", ex.Message); Assert.AreEqual(Ignition.GetIgnite(null), ex.Ignite); Assert.AreEqual("org.apache.ignite.platform.plugin.PlatformTestPluginException", ex.ClassName); var javaEx = ex.InnerException as JavaException; Assert.IsNotNull(javaEx); Assert.AreEqual("Baz", javaEx.JavaMessage); Assert.AreEqual("org.apache.ignite.platform.plugin.PlatformTestPluginException", javaEx.JavaClassName); Assert.IsTrue(javaEx.Message.Contains( "at org.apache.ignite.platform.plugin.PlatformTestPluginTarget.processInLongOutLong")); }
public void TestMetricsPropagation() { var ignite = Ignition.GetIgnite(); using (var inStream = IgniteManager.Memory.Allocate().GetStream()) { var result = ignite.GetCompute().ExecuteJavaTask <bool>( "org.apache.ignite.platform.PlatformCacheWriteMetricsTask", inStream.MemoryPointer); Assert.IsTrue(result); inStream.SynchronizeInput(); var reader = ((Ignite)ignite).Marshaller.StartUnmarshal(inStream); ICacheMetrics metrics = new CacheMetricsImpl(reader); Assert.AreEqual(1, metrics.CacheHits); Assert.AreEqual(2, metrics.CacheHitPercentage); Assert.AreEqual(3, metrics.CacheMisses); Assert.AreEqual(4, metrics.CacheMissPercentage); Assert.AreEqual(5, metrics.CacheGets); Assert.AreEqual(6, metrics.CachePuts); Assert.AreEqual(7, metrics.CacheRemovals); Assert.AreEqual(8, metrics.CacheEvictions); Assert.AreEqual(9, metrics.AverageGetTime); Assert.AreEqual(10, metrics.AveragePutTime); Assert.AreEqual(11, metrics.AverageRemoveTime); Assert.AreEqual(12, metrics.AverageTxCommitTime); Assert.AreEqual(13, metrics.AverageTxRollbackTime); Assert.AreEqual(14, metrics.CacheTxCommits); Assert.AreEqual(15, metrics.CacheTxRollbacks); Assert.AreEqual("myCache", metrics.CacheName); Assert.AreEqual(16, metrics.OverflowSize); Assert.AreEqual(17, metrics.OffHeapGets); Assert.AreEqual(18, metrics.OffHeapPuts); Assert.AreEqual(19, metrics.OffHeapRemovals); Assert.AreEqual(20, metrics.OffHeapEvictions); Assert.AreEqual(21, metrics.OffHeapHits); Assert.AreEqual(22, metrics.OffHeapHitPercentage); Assert.AreEqual(23, metrics.OffHeapMisses); Assert.AreEqual(24, metrics.OffHeapMissPercentage); Assert.AreEqual(25, metrics.OffHeapEntriesCount); Assert.AreEqual(26, metrics.OffHeapPrimaryEntriesCount); Assert.AreEqual(27, metrics.OffHeapBackupEntriesCount); Assert.AreEqual(28, metrics.OffHeapAllocatedSize); Assert.AreEqual(29, metrics.OffHeapMaxSize); Assert.AreEqual(30, metrics.SwapGets); Assert.AreEqual(31, metrics.SwapPuts); Assert.AreEqual(32, metrics.SwapRemovals); Assert.AreEqual(33, metrics.SwapHits); Assert.AreEqual(34, metrics.SwapMisses); Assert.AreEqual(35, metrics.SwapEntriesCount); Assert.AreEqual(36, metrics.SwapSize); Assert.AreEqual(37, metrics.SwapHitPercentage); Assert.AreEqual(38, metrics.SwapMissPercentage); Assert.AreEqual(39, metrics.Size); Assert.AreEqual(40, metrics.KeySize); Assert.AreEqual(true, metrics.IsEmpty); Assert.AreEqual(41, metrics.DhtEvictQueueCurrentSize); Assert.AreEqual(42, metrics.TxThreadMapSize); Assert.AreEqual(43, metrics.TxXidMapSize); Assert.AreEqual(44, metrics.TxCommitQueueSize); Assert.AreEqual(45, metrics.TxPrepareQueueSize); Assert.AreEqual(46, metrics.TxStartVersionCountsSize); Assert.AreEqual(47, metrics.TxCommittedVersionsSize); Assert.AreEqual(48, metrics.TxRolledbackVersionsSize); Assert.AreEqual(49, metrics.TxDhtThreadMapSize); Assert.AreEqual(50, metrics.TxDhtXidMapSize); Assert.AreEqual(51, metrics.TxDhtCommitQueueSize); Assert.AreEqual(52, metrics.TxDhtPrepareQueueSize); Assert.AreEqual(53, metrics.TxDhtStartVersionCountsSize); Assert.AreEqual(54, metrics.TxDhtCommittedVersionsSize); Assert.AreEqual(55, metrics.TxDhtRolledbackVersionsSize); Assert.AreEqual(true, metrics.IsWriteBehindEnabled); Assert.AreEqual(56, metrics.WriteBehindFlushSize); Assert.AreEqual(57, metrics.WriteBehindFlushThreadCount); Assert.AreEqual(58, metrics.WriteBehindFlushFrequency); Assert.AreEqual(59, metrics.WriteBehindStoreBatchSize); Assert.AreEqual(60, metrics.WriteBehindTotalCriticalOverflowCount); Assert.AreEqual(61, metrics.WriteBehindCriticalOverflowCount); Assert.AreEqual(62, metrics.WriteBehindErrorRetryCount); Assert.AreEqual(63, metrics.WriteBehindBufferSize); Assert.AreEqual("foo", metrics.KeyType); Assert.AreEqual("bar", metrics.ValueType); Assert.AreEqual(true, metrics.IsStoreByValue); Assert.AreEqual(true, metrics.IsStatisticsEnabled); Assert.AreEqual(true, metrics.IsManagementEnabled); Assert.AreEqual(true, metrics.IsReadThrough); Assert.AreEqual(true, metrics.IsWriteThrough); } }
public void TearDown() { var ignite = Ignition.GetIgnite(); ignite.GetCacheNames().ToList().ForEach(ignite.DestroyCache); }
public void TestSession() { _dumps = new ConcurrentBag <ICollection <Operation> >(); var ignite = Ignition.GetIgnite(IgniteName); var cache1 = Ignition.GetIgnite(IgniteName).GetCache <int, int>(Cache1); var cache2 = Ignition.GetIgnite(IgniteName).GetCache <int, int>(Cache2); // 1. Test rollback. using (var tx = ignite.GetTransactions().TxStart()) { cache1.Put(1, 1); cache2.Put(2, 2); tx.Rollback(); } Assert.AreEqual(1, _dumps.Count); var ops = _dumps.First(); Assert.AreEqual(1, ops.Count); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.SesEnd && !op.Commit)); _dumps = new ConcurrentBag <ICollection <Operation> >(); // 2. Test puts. using (var tx = ignite.GetTransactions().TxStart()) { cache1.Put(1, 1); cache2.Put(2, 2); tx.Commit(); } Assert.AreEqual(1, _dumps.Count); ops = _dumps.First(); Assert.AreEqual(3, ops.Count); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Write && Cache1.Equals(op.CacheName) && 1.Equals(op.Key) && 1.Equals(op.Value))); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Write && Cache2.Equals(op.CacheName) && 2.Equals(op.Key) && 2.Equals(op.Value))); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.SesEnd && op.Commit)); _dumps = new ConcurrentBag <ICollection <Operation> >(); // 3. Test removes. using (var tx = ignite.GetTransactions().TxStart()) { cache1.Remove(1); cache2.Remove(2); tx.Commit(); } Assert.AreEqual(1, _dumps.Count); ops = _dumps.First(); Assert.AreEqual(3, ops.Count); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Delete && Cache1.Equals(op.CacheName) && 1.Equals(op.Key))); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Delete && Cache2.Equals(op.CacheName) && 2.Equals(op.Key))); Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.SesEnd && op.Commit)); }
/// <summary> /// No-arg constructor. Instantiates the continuous query and performs initial scan of elements that the remote filter /// will populate into the node-local groupers within the mutable grid. /// </summary> public SegmentRetirementQueueManager(bool runLocally) { _log.LogInformation("Establishing segment retirement queue cache context"); // Get the ignite grid and cache references _ignite = DIContext.Obtain <ITRexGridFactory>()?.Grid(StorageMutability.Mutable) ?? Ignition.GetIgnite(TRexGrids.MutableGridName()); var queueCache = _ignite.GetCache <ISegmentRetirementQueueKey, SegmentRetirementQueueItem>(TRexCaches.SegmentRetirementQueueCacheName()); // Todo: Create a thread to periodically (needed if we don't go down the service route // .... _log.LogInformation("Completed segment retirement queue manager initialization"); }
/// <summary> /// Gets the binary store cache. /// </summary> private ICache <TK, TV> GetBinaryStoreCache <TK, TV>() { return(Ignition.GetIgnite(GridName).GetCache <TK, TV>(BinaryStoreCacheName)); }
public void TestNumerics() { var cache = Ignition.GetIgnite().GetOrCreateCache <int, Numerics>(new CacheConfiguration("numerics", new QueryEntity(typeof(int), typeof(Numerics))) { SqlEscapeAll = GetSqlEscapeAll() }); for (var i = 0; i < 100; i++) { cache[i] = new Numerics(((double)i - 50) / 3); } var query = cache.AsCacheQueryable().Select(x => x.Value); var bytes = query.Select(x => x.Byte); var sbytes = query.Select(x => x.Sbyte); var shorts = query.Select(x => x.Short); var ushorts = query.Select(x => x.Ushort); var ints = query.Select(x => x.Int); var uints = query.Select(x => x.Uint); var longs = query.Select(x => x.Long); var ulongs = query.Select(x => x.Ulong); var doubles = query.Select(x => x.Double); var decimals = query.Select(x => x.Decimal); var floats = query.Select(x => x.Float); CheckFunc(x => Math.Abs(x), doubles); CheckFunc(x => Math.Abs((sbyte)x), bytes); CheckFunc(x => Math.Abs(x), sbytes); CheckFunc(x => Math.Abs(x), shorts); CheckFunc(x => Math.Abs((short)x), ushorts); CheckFunc(x => Math.Abs(x), ints); CheckFunc(x => Math.Abs((int)x), uints); CheckFunc(x => Math.Abs(x), longs); CheckFunc(x => Math.Abs((long)x), ulongs); CheckFunc(x => Math.Abs(x), decimals); CheckFunc(x => Math.Abs(x), floats); CheckFunc(x => Math.Acos(x), doubles); CheckFunc(x => Math.Asin(x), doubles); CheckFunc(x => Math.Atan(x), doubles); CheckFunc(x => Math.Atan2(x, 0.5), doubles); CheckFunc(x => Math.Ceiling(x), doubles); CheckFunc(x => Math.Ceiling(x), decimals); CheckFunc(x => Math.Cos(x), doubles); CheckFunc(x => Math.Cosh(x), doubles); CheckFunc(x => Math.Exp(x), doubles); CheckFunc(x => Math.Floor(x), doubles); CheckFunc(x => Math.Floor(x), decimals); CheckFunc(x => Math.Log(x), doubles); CheckFunc(x => Math.Log10(x), doubles); CheckFunc(x => Math.Pow(x, 3.7), doubles); CheckFunc(x => Math.Round(x), doubles); CheckFunc(x => Math.Round(x, 3), doubles); CheckFunc(x => Math.Round(x), decimals); CheckFunc(x => Math.Round(x, 3), decimals); CheckFunc(x => Math.Sign(x), doubles); CheckFunc(x => Math.Sign(x), decimals); CheckFunc(x => Math.Sign(x), floats); CheckFunc(x => Math.Sign(x), ints); CheckFunc(x => Math.Sign(x), longs); CheckFunc(x => Math.Sign(x), shorts); CheckFunc(x => Math.Sign(x), sbytes); CheckFunc(x => Math.Sin(x), doubles); CheckFunc(x => Math.Sinh(x), doubles); CheckFunc(x => Math.Sqrt(x), doubles); CheckFunc(x => Math.Tan(x), doubles); CheckFunc(x => Math.Tanh(x), doubles); CheckFunc(x => Math.Truncate(x), doubles); CheckFunc(x => Math.Truncate(x), decimals); // Operators CheckFunc(x => x * 7, doubles); CheckFunc(x => x / 7, doubles); CheckFunc(x => x % 7, doubles); CheckFunc(x => x + 7, doubles); CheckFunc(x => x - 7, doubles); }
/// <summary> /// Gets the custom store cache. /// </summary> private ICache <int, string> GetCustomStoreCache() { return(Ignition.GetIgnite(GridName).GetCache <int, string>(CustomStoreCacheName)); }
public void TestAffinityKeyMappedWithQueryEntitySpringXml() { TestAffinityKeyMappedWithQueryEntity0(Ignition.GetIgnite("grid-0"), "cache1"); TestAffinityKeyMappedWithQueryEntity0(Ignition.GetIgnite("grid-1"), "cache1"); }