private async Task RunTestCase(Func <AbsolutePath, IContentSession, GrpcCopyClient, Task> testAct, [CallerMemberName] string testName = null)
        {
            var cacheName = testName + "_cache";

            testName += Guid.NewGuid(); // Using a guid to disambiguate scenario name.

            using (var directory = new DisposableDirectory(FileSystem))
            {
                var rootPath = directory.Path;

                var namedCacheRoots = new Dictionary <string, AbsolutePath> {
                    { cacheName, rootPath }
                };
                var grpcPort         = PortExtensions.GetNextAvailablePort();
                var grpcPortFileName = Guid.NewGuid().ToString();
                var configuration    = new ServiceConfiguration(
                    namedCacheRoots,
                    rootPath,
                    42,
                    ServiceConfiguration.DefaultGracefulShutdownSeconds,
                    grpcPort,
                    grpcPortFileName)
                {
                    CopyRequestHandlingCountLimit = _copyToLimit, ProactivePushCountLimit = _proactivePushCountLimit
                };

                var storeConfig = ContentStoreConfiguration.CreateWithMaxSizeQuotaMB(1);
                Func <AbsolutePath, IContentStore> contentStoreFactory = (path) =>
                                                                         new FileSystemContentStore(
                    FileSystem,
                    SystemClock.Instance,
                    directory.Path,
                    new ConfigurationModel(storeConfig));

                var server = new LocalContentServer(FileSystem, Logger, testName, contentStoreFactory, new LocalServerConfiguration(configuration));

                await server.StartupAsync(_context).ShouldBeSuccess();

                var sessionData         = new LocalContentServerSessionData(testName, Capabilities.ContentOnly, ImplicitPin.PutAndGet, pins: null);
                var createSessionResult = await server.CreateSessionAsync(new OperationContext(_context), sessionData, cacheName);

                createSessionResult.ShouldBeSuccess();

                (int sessionId, _)         = createSessionResult.Value;
                using var sessionReference = server.GetSession(sessionId);
                var session = sessionReference.Session;

                // Create a GRPC client to connect to the server
                var port = new MemoryMappedFilePortReader(grpcPortFileName, Logger).ReadPort();
                await _clientCache.UseAsync(new OperationContext(_context), LocalHost, port, async (nestedContext, grpcCopyClient) =>
                {
                    await testAct(rootPath, session, grpcCopyClient);
                    return(Unit.Void);
                });

                await server.ShutdownAsync(_context).ShouldBeSuccess();
            }
        }
示例#2
0
 public LocalCacheServerSessionData(LocalContentServerSessionData other)
     : base(other)
 {
 }