模拟网络断开连接以本地测试分布式应用程序分区 [英] Emulating network disconnects to locally test distributed app partitioning

查看:98
本文介绍了模拟网络断开连接以本地测试分布式应用程序分区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个在本地主机上运行的分布式应用程序实例;每个实例都通过某些端口与他人通信,所有实例共同构成一个整体。
(我实际上是在谈论 ZooKeeper ,在Linux上运行)

I have several instances of a distributed application running on the localhost; every instance communicate with others through certain ports, all instances together make an ensemble. (I'm actually talking about ZooKeeper, running on Linux)

现在我想编写单元测试来模拟整体分区。

例如我有5个实例,我想将它们分为3个和2个两组,以便一个组中的一个实例无法与另一组中的一个实例进行通信。当一台数据中心中有3台计算机,另一台数据中心中有2台计算机,并且数据中心已分区时,它将模拟现实情况。

Now I want to write unit tests to emulate ensemble partitioning.
E.g. I have 5 instances, and I want to split them into two groups of 3 and 2 so that an instance from one group couldn't communicate to an instance from another group. It would emulate real-world situation when 3 machines are in one datacenter, 2 machines are in another one, and datacenters become partitioned.

问题本质上是要制造一个套接字有选择地工作:与一个插座说话,但不与另一个插座说话。我想到的一种解决方案是抽象通信层并将测试规则注入其中(如果我是一个组中的一个实例,则不允许我与另一个组中的一个实例讲话-关闭套接字或忽略数据或其他任何内容)。

The problem is essentially to make a socket work selectively: speak to one socket, but don't speak to another. One solution that comes to mind is to abstract communication layer and inject testing rules into it (in the form of "if I'm an instance from one group I'm not not allowed to speak to an instance from another group -- close socket or ignore data or whatever").

但是也许存在一些工具,也许还有测试框架?
一般来说,如何在分布式应用程序中测试这种情况?

But maybe there exist some tools for this, maybe some testing framework? In general, how do you test such cases in your distributed apps?



P.S.尽管问题被标记为 java(因为ZooKeeper用Java编写),但是听到其他任何语言或独立于语言的解决方案(也许是一些Linux专家的技巧)还是很高兴的。


P.S. Though question is tagged with "java" (since ZooKeeper is written in Java), it'd be great to hear solutions for any other language, or language-independent ones -- maybe some linux guru-tricks.

推荐答案

也许这个答案可以为某人节省几个小时的搜索时间。

Maybe this answer will save a few hours of googling for someone.

Linux有一个非常好的防火墙实用程序, iptables 。它允许您阻止进程之间的通信,例如:

Linux has a very good firewall utility, iptables. It allows you to block communication between processes, like this:

iptables -A INPUT -p tcp --sport <source port> --dport <dest port> -j DROP

尽管无论如何都不是一个成熟的单元测试框架,这对就我而言是手动测试。

While not a full-blown unit testing framework by any measure, this helps a bit with manual testing in my case.

这篇关于模拟网络断开连接以本地测试分布式应用程序分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆