我正在寻找一个从Java 6应用程序中处理数据库死锁的好策略; 可能会有几个并行线程同时写入同一个表.如果数据库(Ingres RDMBS)检测到死锁,它将随机杀死其中一个会话.
考虑到以下要求,处理死锁情况的可接受技术是什么?
到目前为止,我提出的策略是这样的:
short attempts = 0;
boolean success = false;
long delayMs = 0;
Random random = new Random();
do {
try {
//insert loads of records in table 'x'
success = true;
} catch (ConcurrencyFailureException e) {
attempts++;
success = false;
delayMs = 1000*attempts+random.nextInt(1000*attempts);
try {
Thread.sleep(delayMs);
} catch (InterruptedException ie) {
}
}
} while (!success);
Run Code Online (Sandbox Code Playgroud)
它可以以任何方式改进吗?例如,等待固定数量(幻数)秒.是否有不同的策略可以产生更好的结果?
注意:将使用几种数据库级技术来确保死锁在实践中非常罕见.此外,应用程序将尝试避免调度同时写入同一个表的线程.上述情况只是"最糟糕的情况".
注意:插入记录的表被组织为堆分区表并且没有索引; 每个线程都会在其自己的分区中插入记录.
有时,仅运行大型doctests文件的第一部分会很有用.
在代码更改后第一部分中断的情况很多,我想只运行第一部分,直到它通过,然后再次运行整个文件.
我还没有找到一个简单的方法来做到这一点.
假设我用这个文件开始我的doctests:
#!/usr/bin/env python
import doctest
doctest.testfile("scenario.rst")
Run Code Online (Sandbox Code Playgroud)
而scenario.rst看起来像这样:
>>> 'hello world'
'hello world'
>>> exit()
>>> 'this should not be processed anymore'
... lots of lines
>>> 'this should also not be processed'
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我使用exit()函数来演示我的意思,当然它不起作用,因为它被视为异常,doctest愉快地将其视为可以测试的一部分:
**********************************************************************
File "_scenario.rst", line 10, in _scenario.rst
Failed example:
exit()
Exception raised:
Traceback (most recent call last):
File "c:\Python27\lib\doctest.py", line 1254, in __run
compileflags, 1) in test.globs
File "<doctest _scenario.rst[1]>", line 1, in <module>
exit()
File "c:\Python27\lib\site.py", line 372, in __call__
raise SystemExit(code)
SystemExit: …Run Code Online (Sandbox Code Playgroud) 我们设法在eclipse中使用JBehave创建和运行具有国际化故事的测试.一切都很顺利.
但是当我们尝试使用maven插件运行它们时,我们无法解决编码问题(例如,不是从故事中读取"scénario",而是"Scéniio":显然是UTF8编码问题) .
有人找到了一种方法让JBehave使用maven插件阅读UTF8中的故事吗?
我们已经尝试过的:
我们的Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<properties>
<jbehave.version>3.6.5</jbehave.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<resource.encoding>UTF-8</resource.encoding>
</properties>
<build>
<testOutputDirectory>target/classes</testOutputDirectory>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/story</directory>
</testResource>
</testResources>
<plugins>
...
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<additionalBuildcommands>
<buildcommand>com.google.gdt.eclipse.core.webAppProjectValidator</buildcommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<additionalConfig>
<file>
<name>.settings/org.eclipse.core.resources.prefs</name>
<content>
<![CDATA[eclipse.preferences.version=1
encoding/<project>=UTF-8]]>
</content>
</file>
</additionalConfig>
</configuration>
</plugin>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.version}</version>
<executions>
<execution>
<id>run-stories-as-embeddables</id>
<phase>test</phase>
<configuration>
<scope>test</scope>
<includes>
<include>**/*Story.java</include>
</includes>
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>false</ignoreFailureInView>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals> …Run Code Online (Sandbox Code Playgroud) 我在游荡是否有机会使用场景规则,
在我的模型中我有
public function rules()
{
return array(
array('delivery, firstNameBilling, lastNameBilling, addressBilling, cityBilling, countryBilling,
postBilling, telephoneBilling, mailBilling, firstNameDelivery, lastNameDelivery, addressDelivery,
cityDelivery, countryDelivery, postDelivery, telephoneDelivery, mailDelivery', 'required'),
array('active', 'numerical', 'integerOnly'=>true),
);
}
Run Code Online (Sandbox Code Playgroud)
在我看来,我有类似的东西
<tr>
<td>
<p><?php echo $form->label($model,'telephoneBilling'); ?><span>: </span><span class="required">*</span></p>
</td>
<td>
<?php echo $form->textField($model,'telephoneBilling'); ?>
<?php echo $form->error($model,'telephoneBilling'); ?>
</td>
</tr>
</table>
<p><?php echo $form->checkBox($model,'active', array('class' => 'change')); ?>
Delivery information: Please check the box if your delivery address differs from your billing address and enter the
required delivery address …Run Code Online (Sandbox Code Playgroud) 我一直在努力学习Ruby中的Cucumber,我认为最好的方法就是创建自己的项目.但是,我想知道什么是一个好的"给定"条款.
据我所知,"给定"基本上是一个设置,"当"是被测试的功能,"然后"是预期的结果.
例如,让我们假设我正在基于踩着熔岩的实体制作一个Minecraft场景.我目前的GWT看起来像这样:
Scenario: Take damage when I stand in lava.
Given an entity is standing next to a block of lava with 10 health
When the entity steps in the block of lava
Then the entity should take 2 damage
Run Code Online (Sandbox Code Playgroud)
然而,这个"给定"步骤看起来相当'关闭'.我不得不站在一块熔岩旁边让这个场景发挥作用.同样 - 我将如何编写(并测试)一个应该经常发生的场景的GWT - 例如,我怎样才能确保只要我的实体保持在熔岩中,它将继续受到损害?我发现很难编写能够测试实体在熔岩中存放多久的代码.系统如何知道实体在熔岩中停留了多长时间?在我看来,测试那种东西需要我几乎写下世界其他地方,以便能够说"这个实体已经在熔岩中持续x秒,推进模拟,我失去了多少马力"
思考?
我使用Specflow,Selenium WebDriver和C#进行了以下测试:
Scenario Outline: Verify query result
Given I'm logged in
When I enter "<query>"
Then I should see the correct result
Examples:
| query |
| Query1 |
| Query2 |
| Query3 |
Run Code Online (Sandbox Code Playgroud)
在每个方案之后,我将屏幕截图保存到基于ScenarioContext.Current.ScenarioInfo.Title命名的文件中。但是,我找不到区分这些迭代的好方法,因此屏幕截图被覆盖了。我可以在“示例”表中添加一列,但我想要一个更通用的解决方案...
有没有办法知道正在执行哪个迭代?
我正在使用jbehave和jbehave maven插件来运行一组场景测试.
让我的测试类扩展JUnitStories,一切都运行良好.唯一的问题是,我不能停止运行测试...
每次我运行maven安装目标时,它都会运行测试.我尝试在下面添加跳过方案配置文件,但它不会阻止测试运行.
<profile>
<id>skipScenarios</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
我也尝试使用exclude标签而不是skip,并排除我的方案类,但没有运气.
我非常感谢你们的任何洞察力或想法!谢谢!
我要登录一次,然后在关闭浏览器之前运行几个方案(假设有7个方案)。
我使用Background而不是在每个场景中都登录了Given,但是似乎每次运行场景时,它都首先登录。
这减慢了我的测试速度。
我想做的事:
登录并在同一浏览器窗口上运行多个方案,然后在完成后将其关闭。
我有MyEntity.php模型.作为模型脚本的一部分,有一些规则和一些场景定义:
public function rules()
{
return [
[['myentity_id', 'myentity_title', 'myentity_content', 'myentity_date'], 'required'],
[['myentity_id'], 'integer'],
[['myentity_title', 'myentity_content'], 'string', 'max' => 120],
[['myentity_date'], 'safe'],
];
}
public function scenarios()
{
$scenarios = parent::scenarios();
$scenarios['scenario_one'] = ['myentity_id', 'myentity_title'];
$scenarios['scenario_two'] = ['myentity_id', 'myentity_content'];
return $scenarios;
}
Run Code Online (Sandbox Code Playgroud)
我需要能够有不同的场景,并且对于不同的操作,只有某些验证(通过参数)才能激活.例如,scenario_one for actionOne,scenario_two for actionTwo等.
以下是控制器中的一小部分代码:
public function actionOne($id)
{
$modelMyEntity = $this->findModel($id);
$modelMyEntity->scenario = 'scenario_one';
.
.
.
}
public function actionTwo($id)
{
$modelMyEntity = $this->findModel($id);
$modelMyEntity->scenario = 'scenario_two';
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
现在我想要一个scenario_three,根本不应该有任何验证.我将在代码中进行额外的检查,以防止在数据库中存储时出现故障.我只需要确保没有应用任何验证,因为它阻止我的表单提交.如果我不应用任何方案,则应用默认方案(所有列出的验证都将处于活动状态,这与我需要的方案完全相反).