Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions sample/SampleWebApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Enyim.Caching;
using Enyim.Caching.Configuration;
using Enyim.Caching.SampleWebApp.Models;
using Enyim.Caching.SampleWebApp.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace Enyim.Caching.SampleWebApp.Controllers
{
public class HomeController : Controller
{
private readonly IMemcachedClient _memcachedClient;
private readonly IMemcachedClient _postbodyMemcachedClient;
private readonly MemcachedClientOptions options;
private readonly IBlogPostService _blogPostService;
private readonly ILogger _logger;
public static readonly string CacheKey = "blogposts-recent";
public static readonly string PostbodyCacheKey = "postbody";

public HomeController(
IMemcachedClient memcachedClient,
IOptions<MemcachedClientOptions> optionsAccessor,
IMemcachedClient<PostBody> postbodyMemcachedClient,
IBlogPostService blogPostService,
ILoggerFactory loggerFactory)
{
_memcachedClient = memcachedClient;
options = optionsAccessor.Value;
_postbodyMemcachedClient = postbodyMemcachedClient;
_blogPostService = blogPostService;
_logger = loggerFactory.CreateLogger<HomeController>();
Expand Down Expand Up @@ -53,5 +56,12 @@ public async Task<IActionResult> Postbody()
var result = await _postbodyMemcachedClient.GetAsync<string>(PostbodyCacheKey);
return result.Success ? Ok() : StatusCode(500);
}

public IActionResult Uptime()
{
var server = options.Servers.First();
var uptime = _memcachedClient.Stats().GetUptime(new DnsEndPoint(server.Address, server.Port));
return Json(uptime);
}
}
}
11 changes: 1 addition & 10 deletions sample/SampleWebApp/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Enyim.Caching;
using Enyim.Caching.SampleWebApp.Models;
using Enyim.Caching.SampleWebApp.Models;
using Enyim.Caching.SampleWebApp.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Enyim.Caching.SampleWebApp
{
Expand Down
25 changes: 18 additions & 7 deletions test/SampleWebApp.IntegrationTests/HomeControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Enyim.Caching;
using Enyim.Caching;
using Enyim.Caching.SampleWebApp;
using Enyim.Caching.SampleWebApp.Controllers;
using Enyim.Caching.SampleWebApp.Models;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http.Json;
using System.Threading.Tasks;
using Xunit;

namespace SampleWebApp.IntegrationTests
Expand Down Expand Up @@ -45,5 +45,16 @@ public async Task Get_postbody_from_cache_ok()
var response = await httpClient.GetAsync("/home/postbody");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
public async Task Get_uptime_test()
{
var httpClient = _factory.CreateClient();
var response = await httpClient.GetAsync("/home/uptime");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var uptime = await response.Content.ReadFromJsonAsync<TimeSpan>();
Console.WriteLine("uptime: " + uptime);
Assert.True(uptime > TimeSpan.Zero);
}
}
}
Loading