标签: scenarios

多线程 - 避免和处理数据库死锁

我正在寻找一个从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)

它可以以任何方式改进吗?例如,等待固定数量(幻数)秒.是否有不同的策略可以产生更好的结果?

注意:将使用几种数据库级技术来确保死锁在实践中非常罕见.此外,应用程序将尝试避免调度同时写入同一个表的线程.上述情况只是"最糟糕的情况".

注意:插入记录的表被组织为堆分区表并且没有索引; 每个线程都会在其自己的分区中插入记录.

java algorithm ingres scenarios database-deadlocks

5
推荐指数
1
解决办法
5637
查看次数

如何在中间终止python 2 doctest文件?

有时,仅运行大型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)

python doctest scenarios

5
推荐指数
1
解决办法
326
查看次数

Maven JBehave:编码故事UTF8

我们设法在eclipse中使用JBehave创建和运行具有国际化故事的测试.一切都很顺利.

但是当我们尝试使用maven插件运行它们时,我们无法解决编码问题(例如,不是从故事中读取"scénario",而是"Scéniio":显然是UTF8编码问题) .

有人找到了一种方法让JBehave使用maven插件阅读UTF8中的故事吗?

我们已经尝试过的:

  • 添加-Dfile.encoding = UTF-8选项
  • 使用UTF8更改关键字文件
  • 改变ISO =>中的整个项目编码,但是不适用于需要在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)

encoding scenarios utf-8 jbehave maven

5
推荐指数
1
解决办法
4119
查看次数

yii中验证规则的场景

我在游荡是否有机会使用场景规则,

在我的模型中我有

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>:&nbsp;</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)

php validation scenarios yii yii-validation

5
推荐指数
1
解决办法
1万
查看次数

我如何才能在黄瓜中最好地表达这种与时间相关的情景?

我一直在努力学习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秒,推进模拟,我失去了多少马力"

思考?

ruby bdd scenarios acceptance-testing cucumber

5
推荐指数
1
解决办法
646
查看次数

如何获得方案大纲示例的迭代编号

我使用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命名的文件中。但是,我找不到区分这些迭代的好方法,因此屏幕截图被覆盖了。我可以在“示例”表中添加一列,但我想要一个更通用的解决方案...

有没有办法知道正在执行哪个迭代?

c# scenarios specflow

5
推荐指数
1
解决办法
1164
查看次数

使用场景大纲时,如何在specflow中改进自动生成的名称

我只是一个使用Specflow进行测试的新手,当我使用Scenario Outline时我遇到了一个问题.

我的功能文件如下: 功能文件 功能文件 以下是名称是自动生成的 名称. 名称

我只想为表格大纲中的每一行附加测试用例ID,有什么方法可以控制它吗?

我这样做是因为我需要测试的测试用例的数量可以达到1000.因此,如果我可以将测试用例ID附加到Specflow自动生成的名称的后缀中,我可以节省将测试用例映射到测试结果.

testing bdd scenarios cucumber specflow

5
推荐指数
1
解决办法
1374
查看次数

JBehave&Maven - 如何跳过场景测试

我正在使用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,并排除我的方案类,但没有运气.

我非常感谢你们的任何洞察力或想法!谢谢!

scenarios maven-plugin jbehave maven

4
推荐指数
1
解决办法
4822
查看次数

运行一次登录方案,然后运行多个方案

我要登录一次,然后在关闭浏览器之前运行几个方案(假设有7个方案)。

我使用Background而不是在每个场景中都登录了Given,但是似乎每次运行场景时,它都首先登录。

这减慢了我的测试速度。

我想做的事:

登录并在同一浏览器窗口上运行多个方案,然后在完成后将其关闭。

c# scenarios specflow

4
推荐指数
1
解决办法
1857
查看次数

如何在没有验证规则的Yii2中创建场景?

我有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,根本不应该有任何验证.我将在代码中进行额外的检查,以防止在数据库中存储时出现故障.我只需要确保没有应用任何验证,因为它阻止我的表单提交.如果我不应用任何方案,则应用默认方案(所有列出的验证都将处于活动状态,这与我需要的方案完全相反).

validation scenarios validationrules yii2 yii-validation

3
推荐指数
1
解决办法
1734
查看次数