小编And*_*dna的帖子

POSIX 队列和 msg_max

我在玩 POSIX 队列,但遇到了一个问题。创建新队列时,我可以指定例如消息的大小以及队列中可以有多少消息。我的正常限制是 10,见

/proc/sys/fs/mqueue/msg_max
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法可以在程序执行期间更改它,除了

echo number > /proc/sys/fs/mqueue/msg_max
Run Code Online (Sandbox Code Playgroud)

也许存在一些设置这些东西的系统调用。

linux posix message-queue

6
推荐指数
1
解决办法
6911
查看次数

Play框架 - 测试POST控制器方法

我想在我的控制器中测试我的一个POST方法,所以我写了这样的东西:

@Test
    public void shouldSaveNewCollectionToDatabase(){
        String body = "{\"name\":\"collectionName\", \"owner\": {}}";
        JsonNode json = Json.parse(body);
        FakeRequest request = new FakeRequest(POST, "/rest/collections/add").withJsonBody(json);

        Result result = callAction(controllers.routes.ref.SetsAndCollections.postCollection(), request);
        verify(questionSetCollectionDAO).save(any(QuestionSetCollection.class));
    }
Run Code Online (Sandbox Code Playgroud)

问题是,此测试失败,因为根本没有调用控制器方法,所以我的questionSetCollectionDAO方法不会被调用.

我事件在方法的顶部放置了一些打印:

@BodyParser.Of(Json.class)
@play.db.jpa.Transactional
public static Result postCollection(){
    System.out.println("I am here");
...
Run Code Online (Sandbox Code Playgroud)

我在控制台上看不到任何输出.

如果这不是我用虚假请求调用控制器方法的方式,我该怎么办呢?

我读到了fakeApplication但是我还有其他方法可以对POST控制器方法进行一些简单的测试吗?

java unit-testing playframework-2.1

6
推荐指数
1
解决办法
3783
查看次数

angularjs和spring mvc - 在一个请求中上传多个文件

我想在我的Web应用程序中实现文件上载,我angular.js在客户端和spring mvc服务器端使用.

我设法使用https://github.com/danialfarid/angular-file-upload获得单个文件上传和多个文件上传工作.问题是,当我上传多个文件时,每个文件都作为单独的请求来到我这里(在阅读示例代码后这是明显的事件):

//inject angular file upload directives and service.
angular.module('myApp', ['angularFileUpload']);

var MyCtrl = [ '$scope', '$upload', function($scope, $upload) {
  $scope.onFileSelect = function($files) {
    //$files: an array of files selected, each file has name, size, and type.
    for (var i = 0; i < $files.length; i++) {
      var $file = $files[i];
      $scope.upload = $upload.upload({
        url: 'server/upload/url', //upload.php script, node.js route, or servlet url
        // method: POST or PUT,
        // headers: {'headerKey': 'headerValue'}, withCredential: …
Run Code Online (Sandbox Code Playgroud)

file-upload spring-mvc angularjs

6
推荐指数
1
解决办法
3071
查看次数

UML 关联类 - 澄清

我正在阅读 Martin Fowler 的“UML distilled”,在阅读关联类的过程中,我得到了这句话:

您从关联类中获得什么好处来抵消您必须添加的额外符号

记住?关联类增加了一个额外的约束,因为它只能有一个实例

任何两个参与对象之间的关联类。

然后有一个例子,但我想确保我做对了,例如,如果我得到:

 ---------            ---------
|         |*        *|         |
| CLASS A |----------| CLASS B |
|         |     |    |         |
 ---------      |     ---------
                |
          ______|______
         |             |
         |             |
         |  CLASS C    |
         |             |
         |_____________|
Run Code Online (Sandbox Code Playgroud)

那么,对于每一对不同的(A 的实例,B 的实例),只存在一个类 C 的实例。

因此,如果我采用 A1,A2,B1,B2-instances 那么对于 (A1,B1) (A1,B2) (A2,B1) (A2,B2) 我会得到 4 个 C 实例,仅此而已?

uml associations

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

C中的信号处理 - 中断中断

当我的程序同时处理其他信号时,我想知道是否有可能被信号中断,我试图用以下方法模拟它:

#include<signal.h>
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<string.h>

void sig_output()
{
    sigset_t set;
    sigprocmask(0,NULL,&set);
    printf("currently blocking:");
    if (sigismember(&set,SIGUSR1))
        printf("\nSIGUSR1");
    if(sigismember(&set,SIGUSR2))
        printf("\nSIGUSR2");
    printf("\n");
    return ;
}

void sig_handler(int sig)
{
    raise(SIGUSR1);    
    printf("start\n");
    if (sig==SIGUSR1)
        printf("SIGUSR1\n");
    else if (sig==SIGUSR2)
        printf("SIGUSR2\n");
    printf("end\n");
    return ;
}

void other_sig_handler(int sig)
{  
    printf("start - other\n");
    if (sig==SIGUSR1)
        printf("SIGUSR1\n");
    else if (sig==SIGUSR2)
        printf("SIGUSR2\n");
    printf("end - other\n");
    return ;
}

int main()
{
    sig_output();
    struct sigaction a;
    a.sa_handler=sig_handler;
    a.sa_flags=0;
    sigset_t set,old;
    //blocking SIGUSR1,SIGUSR2
    sigemptyset(&set);
    sigaddset(&set,SIGUSR1);
    sigaddset(&set,SIGUSR2);
    printf("blocking SIGUSR1, SIGUSR2\n"); …
Run Code Online (Sandbox Code Playgroud)

c signals

5
推荐指数
2
解决办法
6696
查看次数

C中非常简单的服务器

作为其中一个配置,我们必须在C中使用一些客户端实现非常简单的服务器.我们的想法是使用系统V IPC队列,我们​​创建一个客户端注册的队列,然后为每个客户端创建一个带有消息的队列.我想知道服务器部分.我应该有这样的事情:

while(1)
{
  //some queue using code
  sleep(100);
}
Run Code Online (Sandbox Code Playgroud)

因此,对于每个时间间隔,我检查每个队列并执行我必须做的事情,或者我应该使用信号通知服务器至少有一个队列已准备好进行管理.

它是如何在普通服务器中完成的,它们是否有一段时间间隔,之后它们会检查他们需要做的所有事情,或者有更合适的方法来执行此操作?

c client-server

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

Twitter引导程序 - 嵌套行与多行

我开始使用Twitter bootstrap来处理我正在处理的这个应用程序.

我阅读了有关在固定网格系统和流体系统中嵌套行的文档.

现在,我想做这样的事情

在此输入图像描述

所以我当然可以这样做

<div class="container">
    <div class="row">
        <div class="span 12">red</div>
        <div class="row">
            <div class="span 3">yellow</div>
            <div class="span 9">green</div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想我会得到我想要的东西.但我想知道做的后果是什么

<div class="container">
    <div class="row">
        <div class="span 12">red</div>
    </div>
    <div class="row">
        <div class="span 3">yellow</div>
        <div class="span 9">green</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我现在在浏览器中看不出任何差异,但我想知道如果我在单个container标签中包含多个行元素会发生什么.行嵌套是创建像我展示的东西的唯一正确方法吗?可以这么说,我设计的这两种实现有什么区别?

html twitter-bootstrap

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

angularjs - 测试控制器

我刚刚开始使用angular,我想为我的控制器编写一些简单的单元测试,这是我得到的.

app.js:

'use strict';


// Declare app level module which depends on filters, and services
angular.module('Prototype', ['setsAndCollectionsService']).
  config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/dashboard', {templateUrl: 'partials/dashboard.html', controller: 'DashboardController'});
    $routeProvider.when('/setsAndCollections', {templateUrl: 'partials/setsAndCollections.html', controller: SetsAndCollectionsController});
    $routeProvider.when('/repetition', {templateUrl: 'partials/repetition.html', controller: RepetitionController});
    $routeProvider.otherwise({redirectTo: '/dashboard'});
  }]);
Run Code Online (Sandbox Code Playgroud)

和controllers.js

'use strict';

/* Controllers */

    var myApp = angular.module('Prototype');

    myApp.controller('DashboardController', ['$scope', function (scope) {
        scope.repeats = 6;
    }]);

/*function DashboardController($scope) {
 $scope.repeats = 5;
 };*/

function SetsAndCollectionsController($scope, $location, collectionsService, repetitionService) {
    $scope.id = 3;
    $scope.collections = collectionsService.getCollections();
    $scope.selectedCollection;
    $scope.repetitionService = repetitionService; …
Run Code Online (Sandbox Code Playgroud)

unit-testing angularjs

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

java字节码-没有ipush指令

作为我学校项目的一部分,我需要深入研究 Java 字节码。我开始编写简单的程序并使用javap实用程序来查看生成的字节码,我有一个关于*ipush指令的问题。

当我查看这段代码的字节码时:

public class Main{
  public static void main(String []args){
    int a;
    a=5;
    a=a+32765;
  }
}
Run Code Online (Sandbox Code Playgroud)

我正进入(状态

public class Main
  SourceFile: "Main.java"
  minor version: 0
  major version: 51
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
  #1 = Methodref          #3.#12         //  java/lang/Object."<init>":()V
  #2 = Class              #13            //  Main
  #3 = Class              #14            //  java/lang/Object
  #4 = Utf8               <init>
  #5 = Utf8               ()V
  #6 = Utf8               Code
  #7 = Utf8               LineNumberTable
  #8 = Utf8               main
  #9 = Utf8 …
Run Code Online (Sandbox Code Playgroud)

java jvm bytecode

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

antlr4生成的文件 - 在运行时需要

我想在我antlr的一个项目中使用库.我浏览了antlr4网站上可用的维基页面并编写了我的语法.

一切看起来不错,但我想知道一些生成的文件.

我有一堆.java文件(Lexer,Parser,Listener,BaseListener),但我也有两个.tokens扩展名的文件.我想知道在运行时生成的解析器和词法分析器是否需要它们,或者它们只是java代码生成的副产品而且我不需要将它们包含在我的项目中?

java antlr

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