Skip to content

Commit

Permalink
remove BinaryFormatter (#409)
Browse files Browse the repository at this point in the history
* remove BinaryFormatter

* chore: fix memcached ut fail

* chore: fix memcached lock ut
  • Loading branch information
catcherwong authored Oct 24, 2022
1 parent c2ccc4a commit 1f34f82
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public void AddServices(IServiceCollection services)
{
services.AddOptions();

services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();

services.Configure(_name, _configure);

services.AddSingleton<EasyCachingCSRedisClient>(x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public void AddServices(IServiceCollection services)
{
services.AddOptions();

services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();

services.AddOptions<ConfluentKafkaBusOptions>()
.Configure(_confluentKafkaBusOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void AddServices(IServiceCollection services)
services.AddOptions();
services.Configure(configure);

services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();
services.AddSingleton<IPooledObjectPolicy<IModel>, ModelPooledObjectPolicy>();
services.AddSingleton<IEasyCachingBus, DefaultRabbitMQBus>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public void AddServices(IServiceCollection services)
services.AddOptions();
services.Configure(_name, configure);

services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();
services.AddSingleton<IRedisSubscriberProvider, RedisSubscriberProvider>(x =>
{
var optionsMon = x.GetRequiredService<IOptionsMonitor<RedisBusOptions>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public void AddServices(IServiceCollection services)
{
services.AddOptions();

services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();

services.AddOptions<ZkBusOptions>()
.Configure(_zkBusOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public void AddServices(IServiceCollection services)
{
services.AddOptions();

services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();


services.Configure(_name, _configure);

services.TryAddSingleton<IEasyCachingProviderFactory, DefaultEasyCachingProviderFactory>();
Expand Down
108 changes: 0 additions & 108 deletions src/EasyCaching.Core/Serialization/DefaultBinaryFormatterSerializer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void AddServices(IServiceCollection services)

services.TryAddSingleton<IEasyCachingProviderFactory, DefaultEasyCachingProviderFactory>();
services.TryAddSingleton<IMemcachedKeyTransformer, DefaultKeyTransformer>();
services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();
services.AddSingleton<EasyCachingTranscoder>(x =>
{
var optionsMon = x.GetRequiredService<IOptionsMonitor<MemcachedOptions>>();
Expand Down
2 changes: 0 additions & 2 deletions src/EasyCaching.Redis/Configurations/RedisOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public RedisOptionsExtension(string name, Action<RedisOptions> configure)
public void AddServices(IServiceCollection services)
{
services.AddOptions();

services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();

services.Configure(_name, configure);

Expand Down
7 changes: 0 additions & 7 deletions test/EasyCaching.PerformanceTests/SerializerBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public abstract class SerializerBenchmark
private DefaultJsonSerializer _json = new DefaultJsonSerializer("json", new JsonSerializerSettings());
private DefaultMessagePackSerializer _messagepack = new DefaultMessagePackSerializer("msgpack", new EasyCachingMsgPackSerializerOptions { });
private DefaultProtobufSerializer _protobuf = new DefaultProtobufSerializer("proto");
private DefaultBinaryFormatterSerializer _binary = new DefaultBinaryFormatterSerializer();
protected MyPoco _single;
protected List<MyPoco> _list;
private int _count;
Expand All @@ -39,12 +38,6 @@ public void Setup()
_list = items;
}

[Benchmark]
public void BinaryFormatter()
{
Exec(_binary);
}

[Benchmark]
public void Json()
{
Expand Down
28 changes: 23 additions & 5 deletions test/EasyCaching.UnitTests/CachingTests/MemcachedProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ protected override IEasyCachingProvider CreateCachingProvider(Action<BaseProvide
x.UseMemcached(options =>
{
options.DBConfig.AddServer("127.0.0.1", 11211);
options.SerializerName = "msg";
additionalSetup(options);
}).UseMemcachedLock());
}).WithMessagePack("msg").UseMemcachedLock());
services.AddLogging();
IServiceProvider serviceProvider = services.BuildServiceProvider();
return serviceProvider.GetService<IEasyCachingProvider>();
Expand Down Expand Up @@ -223,9 +224,18 @@ public MemcachedProviderWithFactoryTest()
IServiceCollection services = new ServiceCollection();
services.AddEasyCaching(x =>
{
x.UseMemcached(options => { options.DBConfig.AddServer("127.0.0.1", 11212); }, SECOND_PROVIDER_NAME)
x.WithMessagePack("msg");
x.UseMemcached(options =>
{
options.DBConfig.AddServer("127.0.0.1", 11212);
options.SerializerName = "msg";
}, SECOND_PROVIDER_NAME)
.UseMemcached(
options => { options.DBConfig.AddServer("127.0.0.1", 11211); }, "MyTest");
options =>
{
options.DBConfig.AddServer("127.0.0.1", 11211);
options.SerializerName = "msg";
}, "MyTest");
});
services.AddLogging();
IServiceProvider serviceProvider = services.BuildServiceProvider();
Expand Down Expand Up @@ -346,6 +356,7 @@ public MemcachedProviderUseEasyCachingTest()
services.AddLogging();
services.AddEasyCaching(option =>
{
option.WithMessagePack("msg");
option.UseMemcached(config =>
{
config.DBConfig = new EasyCachingMemcachedClientOptions
Expand All @@ -355,6 +366,7 @@ public MemcachedProviderUseEasyCachingTest()
new Enyim.Caching.Configuration.Server() {Address = "127.0.0.1", Port = 11212}
}
};
config.SerializerName = "msg";
}, EasyCachingConstValue.DefaultMemcachedName);
});

Expand All @@ -372,7 +384,7 @@ public MemcachedProviderUseEasyCachingWithConfigTest()
{
IServiceCollection services = new ServiceCollection();

var appsettings = " { \"easycaching\": { \"memcached\": { \"MaxRdSecond\": 600, \"dbconfig\": { \"Servers\": [ { \"Address\": \"127.0.0.1\", \"Port\": 11211 } ] } } }}";
var appsettings = " {\"easycaching\":{\"memcached\":{\"MaxRdSecond\":600,\"dbconfig\":{\"Servers\":[{\"Address\":\"127.0.0.1\",\"Port\":11211}]},\"SerializerName\":\"msg\"}}} ";
var path = TestHelpers.CreateTempFile(appsettings);
var directory = Path.GetDirectoryName(path);
var fileName = Path.GetFileName(path);
Expand All @@ -382,7 +394,11 @@ public MemcachedProviderUseEasyCachingWithConfigTest()
configurationBuilder.AddJsonFile(fileName);
var config = configurationBuilder.Build();
services.AddLogging();
services.AddEasyCaching(option => { option.UseMemcached(config, "mName"); });
services.AddEasyCaching(option =>
{
option.WithMessagePack("msg");
option.UseMemcached(config, "mName");
});

IServiceProvider serviceProvider = services.BuildServiceProvider();
_provider = serviceProvider.GetService<IEasyCachingProvider>();
Expand All @@ -407,6 +423,7 @@ public async void NoConnectionTest()
services.AddLogging();
services.AddEasyCaching(option =>
{
option.WithMessagePack("msg");
option.UseMemcached(config =>
{
config.DBConfig = new EasyCachingMemcachedClientOptions
Expand All @@ -422,6 +439,7 @@ public async void NoConnectionTest()
ReceiveTimeout = TimeSpan.FromSeconds(2),
}
};
config.SerializerName = "msg";
}, EasyCachingConstValue.DefaultMemcachedName);
});

Expand Down
11 changes: 8 additions & 3 deletions test/EasyCaching.UnitTests/DistributedLock/MemcachedLockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ public class MemcachedLockTest : DistributedLockTest
{
private static readonly IDistributedLockFactory Factory = new ServiceCollection()
.AddLogging()
.AddEasyCaching(option => option.UseMemcached(config =>
.AddEasyCaching(option =>
{
option.WithMessagePack("msg");
option.UseMemcached(config =>
{
config.SerializerName = "msg";
config.DBConfig = new EasyCachingMemcachedClientOptions
{
Servers =
{
new Server { Address = "127.0.0.1", Port = 11211 }
}
};
})
.UseMemcachedLock())
});
option.UseMemcachedLock();
})
.BuildServiceProvider()
.GetService<MemcachedLockFactory>();

Expand Down

This file was deleted.

0 comments on commit 1f34f82

Please sign in to comment.