コード例 #1
0
        public void PutOnOneCacheGetOnAnotherCache()
        {
            var geodeServer = new GeodeServer();
            var cacheXml    = new CacheXml(new FileInfo("cache.xml"), geodeServer);

            var cacheFactory = new CacheFactory();

            cacheOne = cacheFactory.Create();
            cacheOne.InitializeDeclarativeCache(cacheXml.File.FullName);
            cacheTwo = cacheFactory.Create();
            cacheTwo.InitializeDeclarativeCache(cacheXml.File.FullName);


            var regionForCache1 = cacheOne.GetRegion <string, string>("testRegion1");
            var regionForCache2 = cacheTwo.GetRegion <string, string>("testRegion1");

            const string key            = "hello";
            const string expectedResult = "dave";

            regionForCache1.Put(key, expectedResult, null);
            var actualResult = regionForCache2.Get(key, null);

            Assert.Equal(expectedResult, actualResult);

            cacheXml.Dispose();
            geodeServer.Dispose();
        }
コード例 #2
0
ファイル: CacheXml.cs プロジェクト: mmartell/geode-native
    public CacheXml(FileInfo template, GeodeServer gfs, string regionName = "testRegion")
    {
        string content;

        using (var input = template.OpenText())
        {
            content = input.ReadToEnd();
        }

        content = content.Replace("LOCATOR_PORT", gfs.LocatorPort.ToString());
        content = content.Replace("REGION_NAME", regionName);

        Debug.WriteLine(content);

        var tempFile = new FileInfo(Path.GetTempFileName())
        {
            Attributes = FileAttributes.Temporary
        };

        // Set the Attribute property of this file to Temporary.
        // Although this is not completely necessary, the .NET Framework is able
        // to optimize the use of Temporary files by keeping them cached in memory.
        using (var output = new StreamWriter(tempFile.FullName))
        {
            output.Write(content);
        }

        File = tempFile;
    }
コード例 #3
0
    public void Start()
    {
        var gfs = new GeodeServer();

        Assert.NotNull(gfs);
        Assert.NotEqual(0, gfs.LocatorPort);
        gfs.Dispose();
    }
コード例 #4
0
    public void ConstructAndGenerate()
    {
        using (var gfs = new GeodeServer())
        {
            var template = new FileInfo("cache.xml");
            var cacheXml = new CacheXml(template, gfs);
            Assert.NotNull(cacheXml.File);
            Assert.True(cacheXml.File.Exists);

            using (var input = cacheXml.File.OpenText())
            {
                var content = input.ReadToEnd();
                Assert.True(content.Contains(gfs.LocatorPort.ToString()));
            }
        }
    }
コード例 #5
0
    public void StartTwo()
    {
        var gfs1 = new GeodeServer();

        Assert.NotNull(gfs1);
        Assert.NotEqual(0, gfs1.LocatorPort);

        var gfs2 = new GeodeServer();

        Assert.NotNull(gfs2);
        Assert.NotEqual(0, gfs2.LocatorPort);

        Assert.NotEqual(gfs1.LocatorPort, gfs2.LocatorPort);
        gfs1.Dispose();
        gfs2.Dispose();
    }
コード例 #6
0
    public void DisposeAndCleanup()
    {
        using (var gfs = new GeodeServer())
        {
            FileInfo file;

            var template = new FileInfo("cache.xml");
            using (var cacheXml = new CacheXml(template, gfs))
            {
                Assert.NotNull(cacheXml.File);
                file = cacheXml.File;
                Assert.True(file.Exists);
            }

            file.Refresh();

            // File deletion via File.Delete (inside the file.Refresh() call)
            // is not synchronous so we need to potentially wait until the file
            // has been deleted here
            Assert.True(SpinWait.SpinUntil(() => !file.Exists, 10000));
        }
    }