我正在尝试从boto3 s3客户端对象模拟一个单一方法来抛出异常.但我需要这个类的所有其他方法正常工作.
这样我可以在执行upload_part_copy时测试单个异常测试并发生错误
第一次尝试
import boto3
from mock import patch
with patch('botocore.client.S3.upload_part_copy', side_effect=Exception('Error Uploading')) as mock:
client = boto3.client('s3')
# Should return actual result
o = client.get_object(Bucket='my-bucket', Key='my-key')
# Should return mocked exception
e = client.upload_part_copy()
Run Code Online (Sandbox Code Playgroud)
但是,这会产生以下错误:
ImportError: No module named S3
Run Code Online (Sandbox Code Playgroud)
第二次尝试
在查看了botocore.client.py源代码后,我发现它正在做一些聪明的事情并且该方法upload_part_copy不存在.我发现它似乎在调用,BaseClient._make_api_call所以我试图嘲笑它
import boto3
from mock import patch
with patch('botocore.client.BaseClient._make_api_call', side_effect=Exception('Error Uploading')) as mock:
client = boto3.client('s3')
# Should return actual result
o = client.get_object(Bucket='my-bucket', Key='my-key')
# Should return mocked exception
e …Run Code Online (Sandbox Code Playgroud) 所以我不能在"/etc/httpd/conf.d/vhosts.conf"中获得一个别名,其中包含我的所有虚拟主机:
<VirtualHost *>
ServerName example.com
Alias /ncn /var/www/html/ncn
DocumentRoot /var/www/html/mjp
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我希望我的别名能够工作,所以我可以将example.com/ncn指向"/ var/www/html/ncn".
如果我在"/etc/httpd/conf/httpd.conf"中使用它,而不是我的"/etc/httpd/conf.d/vhosts.conf",这是有效的
有什么想法吗?其他一切似乎都有效,即ServerAlias
干杯,彼得
我已经尝试了网上的一些例子,但是无法让Spring验证我的查询字符串参数.它似乎没有执行REGEX/fail.
package my.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import javax.validation.constraints.Pattern;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
@RestController
public class MyController {
private static final String VALIDATION_REGEX = "^[0-9]+(,[0-9]+)*$";
@RequestMapping(value = "/my/{id}", method = GET)
public myResonseObject getMyParams(@PathVariable("id") String id,
@Valid @Pattern(regexp = VALIDATION_REGEX)
@RequestParam(value = "myparam", required = true) String myParam) {
// Do Stuff!
}
}
Run Code Online (Sandbox Code Playgroud)
目前的行为
PASS - /my/1?myparam=1
PASS - /my/1?myparam=1,2,3
PASS - /my/1?myparam=
PASS - /my/1?myparam=1,bob
Run Code Online (Sandbox Code Playgroud)
期望的行为
PASS - /my/1?myparam=1
PASS - …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Boot创建API,因此希望禁用/error映射.
我在application.properties中设置了以下道具:
server.error.whitelabel.enabled=false
spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false
Run Code Online (Sandbox Code Playgroud)
但是,当我点击时,/error我得到:
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 03 Aug 2016 15:15:31 GMT
Connection: close
{"timestamp":1470237331487,"status":999,"error":"None","message":"No message available"}
Run Code Online (Sandbox Code Playgroud)
要求的结果
HTTP/1.1 404 Internal Server Error
Server: Apache-Coyote/1.1
Run Code Online (Sandbox Code Playgroud) 我希望在Spring Context中执行一些设置方法.
我目前有以下代码,但它不起作用,因为我说它们是beans没有返回类型.
@Configuration
@Component
public class MyServerContext {
...
// Works
@Bean
public UserData userData() {
UserData userData = new AWSUserDataFetcher(urlUtil()).fetchUserData();
return userData;
}
// Doesn't work
@Bean
public void setupKeyTrustStores() {
// Setup TrustStore & KeyStore
System.setProperty(SYS_TRUST_STORE, userData().get(TRUST_STORE_PATH));
System.setProperty(SYS_TRUST_STORE_PASSWORD, userData().get(TRUST_STORE_PASSWORD));
System.setProperty(SYS_KEY_STORE, userData().get(KEY_STORE_PATH));
System.setProperty(SYS_KEY_STORE_PASSWORD, userData().get(KEY_STORE_PASSWORD));
// Prevents handshake alert: unrecognized_name
System.setProperty(ENABLE_SNI_EXTENSION, "false");
}
...
}
Run Code Online (Sandbox Code Playgroud)
如何在@Configuration没有@Bean注释的情况下自动运行此方法?
我目前有这个RequestMapping,我通过正则表达式使用验证:
@RequestMapping(value = "/example/{id}", method = GET)
public Response getExample(
@PathVariable("id") String id,
@RequestParam(value = "myParam", required = true) @Valid @Pattern(regexp = MY_REGEX) String myParamRequest,
@RequestParam(value = "callback", required = false) String callback,
@RequestHeader(value = "X-API-Key", required = true) @Valid @Pattern(regexp = SEGMENTS_REGEX) String apiKeyHeader) {
// Stuff here...
}
Run Code Online (Sandbox Code Playgroud)
然而,正则表达是不够的.相反,我想对header属性进行一些自定义验证,即
if (!API_KEY_LIST.contains(apiKeyHeader)) {
throw Exception();
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?
附加到[][]string分析后显示应用程序使用大约145MiB的内存.
defer profile.Start(profile.MemProfile).Stop()
f, _ := os.Open("test.csv") // 100 MiB File
r := csv.NewReader(f)
var records [][]string
for {
values, err := r.Read()
if err == io.EOF {
break
}
records = append(records, values)
}
Run Code Online (Sandbox Code Playgroud)
将切片存储在结构中并附加应用程序使用大约260MiB的内存时.
defer profile.Start(profile.MemProfile).Stop()
type record struct {
values []string
}
f, _ := os.Open("test.csv") // 100 MiB File
r := csv.NewReader(f)
var records []record
for {
values, err := r.Read()
if err == io.EOF {
break
}
r := record{values: values}
records = …Run Code Online (Sandbox Code Playgroud) 在互联网上搜索嵌入式 Java AWS S3 模拟的良好解决方案后,S3Ninja和S3Proxy似乎是最受欢迎的解决方案。
但是,似乎没有一种简单的方法可以以编程方式启动它们。放弃 S3Ninja 后,我尝试使用 S3Proxy 来完成,但效果不佳。
Maven 依赖项
<dependency>
<groupId>org.gaul</groupId>
<artifactId>s3proxy</artifactId>
<version>${s3proxy.version}</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
代码
String endpoint = "http://127.0.0.1:8085";
URI uri = URI.create(endpoint);
Properties properties = new Properties();
properties.setProperty("s3proxy.authorization", "none");
properties.setProperty("s3proxy.endpoint", endpoint);
properties.setProperty("jclouds.provider", "filesystem");
properties.setProperty("jclouds.filesystem.basedir", "/tmp/s3proxy");
ContextBuilder builder = ContextBuilder
.newBuilder("filesystem")
.credentials("x", "x")
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.overrides(properties);
BlobStoreContext context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
S3Proxy s3Proxy = S3Proxy.builder().awsAuthentication("x", "x").endpoint(uri).keyStore("", "").blobStore(blobStore).build();
s3Proxy.start();
BasicAWSCredentials awsCredentials = new BasicAWSCredentials("x", "x");
AmazonS3Client client = new AmazonS3Client(awsCredentials, …Run Code Online (Sandbox Code Playgroud) java integration-testing amazon-s3 amazon-web-services s3proxy
我有一个GlobalExceptionHandler捕获异常并返回HTTP错误代码的。
@ControllerAdvice
@Component
public class GlobalExceptionHandler {
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
...
// 404 - Not Found
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public void requestHandlingNoHandlerFound(HttpServletRequest request, Exception exception) {
logger.error("Error Not Found (404): " + exception.getMessage());
}
...
}
Run Code Online (Sandbox Code Playgroud)
这可以正常工作,并显示404。但是HTTP响应看起来像这样:
HTTP/1.1 404
X-Application-Context: application:8080
Content-Length: 0
Date: Wed, 03 Aug 2016 14:36:52 GMT
Run Code Online (Sandbox Code Playgroud)
但应返回:
HTTP/1.1 404 Not Found
X-Application-Context: application:8080
Content-Length: 0
Date: Wed, 03 Aug 2016 14:36:52 GMT
Run Code Online (Sandbox Code Playgroud)
该Not Found部分丢失。其他错误也一样。例如500 - Internal …
我有一个Spring Boot应用程序,该应用程序需要数百万个键值对并将它们插入Redis。
目前,我一次使用multiSet1,000个键值对的方法。
@Autowired
private final StringRedisTemplate template;
...
Map<String, String> keyValuePairs = new HashMap<>();
template.opsForValue().multiSet(keyValuePairs);
Run Code Online (Sandbox Code Playgroud)
但是,我们还需要为每对设置一个TTL。似乎没有办法用来做到这一点multiSet。有一种方法,set但这必须被调用数百万次,因此可能效率不高。
// For each key value pair
template.opsForValue().set(key, value, timeout, unit);
Run Code Online (Sandbox Code Playgroud)
有谁知道这样做或set以高性能方式使用的方式?
谢谢
我想让 UL (黄色)水平包裹 LI 列表元素(紫色),而 UL 上没有任何固定宽度。已为本示例添加了包装。
超文本标记语言
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.wrap {
background: green;
width: 500px;
padding: 10px 20px;
}
li {
display: inline-block;
width: 70px;
height: 50px;
background: purple;
list-style: none;
}
ul {
background: yellow;
margin: 0; padding: 0;
}
Run Code Online (Sandbox Code Playgroud)
现在

期望的

CodePen在这里: http: //codepen.io/ptimson/pen/IrCHB
我正在尝试将以下内容创建为 SVG:

即带有水平虚线的圆圈。
这是我目前拥有的 SVG 代码……由 Adobe Illustrator 生成:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="165px" height="165px" viewBox="0 0 165 165" enable-background="new 0 0 165 165" xml:space="preserve">
<g>
<circle fill="none" stroke="#000000" stroke-width="9" stroke-miterlimit="23" stroke-dasharray="1.0048,6.0288" cx="82.453" cy="82.563" r="75"/>
</g>
</svg>Run Code Online (Sandbox Code Playgroud)
但是当我在 Chrome 中打开时,线条似乎非常参差不齐,有些线条比其他线条更近。

有没有更好的方法来生成这个 SVG 还是我应该简单地使用 PNG?
我能够获得Spring Boot集成以生成随机自由端口以启动自身.但我还需要Redis的免费端口.
@ContextConfiguration(classes = {MyApplication.class}, loader = SpringApplicationContextLoader.class)
@WebIntegrationTest(randomPort = true, value = "server.port:0")
@ActiveProfiles(profiles = {"local"})
public class SegmentSteps {
private static final String HOST_TEMPLATE = "http://localhost:%s";
// Needs to be a random open port
private static final int REDIS_PORT = 6380;
private String host;
@Value("${local.server.port}")
private int serverPort;
private RedisServer redisServer;
@Before
public void beforeScenario() throws Exception {
host = String.format(HOST_TEMPLATE, serverPort);
redisServer = RedisServer.builder()
.redisExecProvider(RedisExecProvider.defaultProvider())
.port(REDIS_PORT)
.setting("bind 127.0.0.1")
.build();
redisServer.start();
}
...
}
Run Code Online (Sandbox Code Playgroud)
关于如何实现这一点的任何想法?
java ×8
spring ×7
spring-boot ×7
spring-mvc ×4
html ×2
amazon-s3 ×1
annotations ×1
apache ×1
boto ×1
boto3 ×1
botocore ×1
css ×1
go ×1
httpd.conf ×1
memory ×1
memory-leaks ×1
mocking ×1
python ×1
redis ×1
rest ×1
s3proxy ×1
slice ×1
spring-rest ×1
spring-test ×1
struct ×1
svg ×1
validation ×1