mdevilliers / Toxiproxy.Net

Toxiproxy.Net is a .Net client for Shopify's Toxiproxy. Toxiproxy is a proxy to test your system by simulating network failure.
MIT License
52 stars 10 forks source link

Unable to add latency #7

Closed federicoorlandini closed 8 years ago

federicoorlandini commented 8 years ago

Hi, I'm using your client to simulate a latency on a Redis server. I'using the following code: `var client = Connection.Client();

        var proxy = client.FindProxy(ProxyName);
        var upstreams = proxy.UpStreams();
        var latency = upstreams.LatencyToxic;
        latency.Latency = 10000;
        latency.Update();`

but I get this exception: InvalidCastException: Unable to cast object of type 'System.Int64' to type 'Toxiproxy.Net.ToxiproxiErrorMessage'. in this line of code: var upstreams = proxy.UpStreams();

This is the code I use to create the proxy:

`private static void CreateRedisProxy() { var client = Connection.Client();

        //proxy all traffic from localhost:6380 to localhost:6379
        var localToRedisProxy = new Proxy()
        {
            Name = ProxyName,
            Enabled = true,
            Listen = "localhost:6380",
            Upstream = "localhost:6379"
        };

        client.Add(localToRedisProxy);
    }`

Any idea why I get this exception? Thank you for your help.

Regards, Federico

federicoorlandini commented 8 years ago

I think I found the problem: the client tries to read data from the following address: http://localhost:8474/proxies/localToRedis/upstream but the server respondes with a 404 Not Found.

mdevilliers commented 8 years ago

Hey,

Would it be possible to get the full stack trace?

Could you also confirm if which version of toxiproxy you are using? Is it the one bundled into the nuget package/repo or one from the shopify project itself?

Thanks,

Mark

federicoorlandini commented 8 years ago

Hi Mark,

I'm using ToxiProxy 2.0 (Windows binaries). The exception is> System.InvalidCastException with Message: "Unable to cast object of type 'System.Int64' to type 'Toxiproxy.Net.ToxiproxiErrorMessage". StackTrace:

at RestSharp.SimpleJson.DeserializeObject[T](String json) at Toxiproxy.Net.ToxiproxyBaseClient.b__2(IRestResponse resp) in d:\git2\Toxiproxy.Net\Toxiproxy.Net\ToxiproxyBaseClient.cs:line 16 at RestSharp.RestClient.Deserialize[T](IRestRequest request, IRestResponse raw) at RestSharp.RestClient.Execute[T](IRestRequest request) at Toxiproxy.Net.Client.FindUpStreamToxicsForProxy(String proxyName) in d:\git2\Toxiproxy.Net\Toxiproxy.Net\Client.cs:line 126 at Toxiproxy.Net.Client.FindUpStreamToxicsForProxy(Proxy proxy) in d:\git2\Toxiproxy.Net\Toxiproxy.Net\Client.cs:line 113 at Toxiproxy.Net.Proxy.UpStreams() in d:\git2\Toxiproxy.Net\Toxiproxy.Net\Proxy.cs:line 16 at ConsoleApplication1.Program.AddLatency() in c:\Users\forlandini\Desktop\ToxiProxy\Client.NET\ConsoleApplication1\ConsoleApplication1\Program.cs:line 27 at ConsoleApplication1.Program.Main(String[] args) in c:\Users\forlandini\Desktop\ToxiProxy\Client.NET\ConsoleApplication1\ConsoleApplication1\Program.cs:line 19 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

I'll try to take a look in it this evening. I really like ToxiProxy and your .NET client project. I would like to contribute :-)

Regards, Federico

2016-06-28 9:36 GMT+02:00 Mark deVilliers notifications@github.com:

Hey,

Would it be possible to get the full stack trace?

Could you also confirm if which version of toxiproxy you are using? Is it the one bundled into the nuget package/repo or one from the shopify project itself?

Thanks,

Mark

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mdevilliers/Toxiproxy.Net/issues/7#issuecomment-228974262, or mute the thread https://github.com/notifications/unsubscribe/AJkhQABp49rUuf5Sbx-o3MPRia_eDHyBks5qQM7ygaJpZM4I-9Nb .

Ing. Federico Orlandini Tel. 340-2571882 skype: federico.orlandini

mdevilliers commented 8 years ago

Thanks for getting back to me.

I think the issue is that they changed the http api in toxiproxy 2.*. If you use the the bundled executable on windows or the 1.2.1 version from their release on linux or mac it should work fine.

Glad to hear you like the project. If you wanted to contribute ( I can add you as a contributor and help as much as I can however I do very little .net work these days) or fork it (and I'll point to the new fork and/or hand over the nuget api keys and ownership) please feel free - I think it would be good to have a .net client for the latest version.

Hope to hear from you,

Mark

federicoorlandini commented 8 years ago

It would be very happy to become a contributor. I think the ToxiProxy is a useful tool and it would be very nice to have a .NET client that works with the version 2.0. Thank you.

Best regards, Federico

2016-06-28 21:47 GMT+02:00 Mark deVilliers notifications@github.com:

Thanks for getting back to me.

I think the issue is that they changed the http api in toxiproxy 2.*. If you use the the bundled executable on windows or the 1.2.1 version from their release on linux or mac it should work fine.

Glad to hear you like the project. If you wanted to contribute ( I can add you as a contributor and help as much as I can however I do very little .net work these days) or fork it (and I'll point to the new fork and/or hand over the nuget api keys and ownership) please feel free - I think it would be good to have a .net client for the latest version.

Hope to hear from you,

Mark

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mdevilliers/Toxiproxy.Net/issues/7#issuecomment-229161362, or mute the thread https://github.com/notifications/unsubscribe/AJkhQOP21atRGr6N0QAGEiEDjBLJY0PVks5qQXptgaJpZM4I-9Nb .

Ing. Federico Orlandini Tel. 340-2571882 skype: federico.orlandini

mdevilliers commented 8 years ago

Awesome,

I've added you as a collaborator - you should get an invite soon.

Did you have a chance to test against the 1.2.1 version of toxiproxy?

Mark

federicoorlandini commented 8 years ago

Hi,

I tested against the 1.2.1 version of the proxy. It works. Yesterday I cloned the your repository on my notebook and I'll start to work on it. Thank you.

Best regards, Federico

2016-06-29 11:20 GMT+02:00 Mark deVilliers notifications@github.com:

Awesome,

I've added you as a collaborator - you should get an invite soon.

Did you have a chance to test against the 1.2.1 version of toxiproxy?

Mark

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mdevilliers/Toxiproxy.Net/issues/7#issuecomment-229303433, or mute the thread https://github.com/notifications/unsubscribe/AJkhQG5W5LPsyGG9_HbIQ42u9_hvqQLpks5qQjjcgaJpZM4I-9Nb .

Ing. Federico Orlandini Tel. 340-2571882 skype: federico.orlandini

federicoorlandini commented 8 years ago

Hi,

If you agree, I'm going to create a new branch called V2. In this branch, I'll create a new namespace V2 where I create a new version of the client and for all the other classes that I need. I'll try to reuse the existing code and abstraction as much as possible. As soon as I'll have something ready, I'll send you a pull request for the code review. What do you think? Is it ok for you?

Regards, Federico

2016-06-30 10:21 GMT+02:00 Mark deVilliers notifications@github.com:

Closed #7 https://github.com/mdevilliers/Toxiproxy.Net/issues/7.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mdevilliers/Toxiproxy.Net/issues/7#event-708826714, or mute the thread https://github.com/notifications/unsubscribe/AJkhQMrE8xuJEz1fffmn7IHvpuy1DKtFks5qQ3yIgaJpZM4I-9Nb .

Ing. Federico Orlandini Tel. 340-2571882 skype: federico.orlandini

mdevilliers commented 8 years ago

Good plan.

The one thing I quite liked in the V1 code were the unit/integration tests e.g. they span up a version of toxiproxy and tested against the real thing. I'd be keen on keepiing that.

The rest feel free to change, revise and tweak at will.

Mark

federicoorlandini commented 8 years ago

Sure. I will add the V2 and refactor the V1 code (just in case) but I'll check the previous tests to have them green.

Thanks. Regards, Federico

2016-07-05 9:39 GMT+02:00 Mark deVilliers notifications@github.com:

Good plan.

The one thing I quite liked in the V1 code were the unit/integration tests e.g. they span up a version of toxiproxy and tested against the real thing. I'd be keen on keepiing that.

The rest feel free to change, revise and tweak at will.

Mark

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mdevilliers/Toxiproxy.Net/issues/7#issuecomment-230407727, or mute the thread https://github.com/notifications/unsubscribe/AJkhQDZWbdKIt0TJk1A4IBtscdb4AbMxks5qSgorgaJpZM4I-9Nb .

Ing. Federico Orlandini Tel. 340-2571882 skype: federico.orlandini

mdevilliers commented 8 years ago

Sorry, I was probably confusing - don't worry about keeping the V1 code working - before we merge the V2 branch we will tag the V1 branch (in case someone needs it and they will always have the nuget packages).

When I mentioned the tests - I liked the way they worked e.g. working against the real toxiproxy I think is a lot more convincing that trying to mock/stub out a toxiproxy API.

Mark

federicoorlandini commented 8 years ago

Ok, no problem. We'll go for integration tests against a real ToxiProxy instance.

:-)

2016-07-05 10:38 GMT+02:00 Mark deVilliers notifications@github.com:

Sorry, I was probably confusing - don't worry about keeping the V1 code working - before we merge the V2 branch we will tag the V1 branch (in case someone needs it and they will always have the nuget packages).

When I mentioned the tests - I liked the way they worked e.g. working against the real toxiproxy I think is a lot more convincing that trying to mock/stub out a toxiproxy API.

Mark

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mdevilliers/Toxiproxy.Net/issues/7#issuecomment-230419378, or mute the thread https://github.com/notifications/unsubscribe/AJkhQKGe3Rk2EMv2UGwtxFi0kDNLXxZ4ks5qShf-gaJpZM4I-9Nb .

Ing. Federico Orlandini Tel. 340-2571882 skype: federico.orlandini