在我的Spring Boot Web应用程序中,我使用MongoDB来存储数据.在应用程序中,我使用扩展的接口访问数据库MongoRepository.
如何为此类存储库类设置单元测试?我想要的是
我尝试过使用Embedded MongoDB,但我无法弄清楚如何从文件中插入testdata.我也尝试使用NoSQLUnit,但SpringApplicationConfiguration与单元测试配置冲突,导致不同的数据库进行读写.
我正在尝试使用RNCryptor加密和解密iOS上的大文件(600 + MB).在github上,我找到了关于如何在流上异步使用库的示例代码.此代码类似于Rob Napier关于同一主题的问题的答案.
但是,虽然我认为我正确实现了代码,但该应用程序使用高达1.5 GB的内存(在iPad 6.1模拟器中).我认为代码应该阻止应用程序在内存中保留多个数据块?出了什么问题?
在我的控制器中,我创建了一个'CryptController',我用加密/解密请求发送消息.
// Controller.m
NSString *password = @"pw123";
self.cryptor = [[CryptController alloc] initWithPassword:password];
//start encrypting file
[self.cryptor streamEncryptRequest:self.fileName andExtension:@"pdf" withURL:[self samplesURL]];
//wait for encryption to finish
NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:1];
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:timeout];
} while (![self.cryptor isFinished]);
Run Code Online (Sandbox Code Playgroud)
在CryptController我有:
- (void)streamEncryptionDidFinish {
if (self.cryptor.error) {
NSLog(@"An error occurred. You cannot trust decryptedData at this point");
}
else {
NSLog(@"%@ is complete. Use it as you like", [self.tempURL …Run Code Online (Sandbox Code Playgroud) 我有实体User和GrantedRole具有双向一对多关系.
当我尝试将GrantedRole添加到Set in User时,没有抛出异常,但是当我调试User和GrantedRole对象的变量时,会有一个读取的描述
com.sun.jdi.InvocationException发生了调用方法.
调试时可以读取变量的不同字段,但是当我选择User中的角色字段或GrantedRole中的用户字段时,我得到与上面相同的描述.当我进入用户的Set of GrantedRole时,我最终找到以下描述:
详细格式化程序错误:发生异常:java.lang.StackOverflowError
我的代码:
public class User {
private Set<GrantedRole> roles = new HashSet<GrantedRole>();
public User() {
super();
}
public User(String name, String password) {
this.name = name;
this.password = password;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
public Set<GrantedRole> getRoles() {
return roles;
}
public void setRoles(Set<GrantedRole> roles) {
this.roles = roles;
}
// equals and hashCode are based on username
// toString is based on all fields
}
public class GrantedRole { …Run Code Online (Sandbox Code Playgroud) 我有实体User,Organization和GrantedRole。它们之间的关系是,GrantedRole定义了用户在组织中的角色。这三个实体都从其超类继承字段“ id”(用@Id注释)。组织没有对GrantedRole或User的引用,这些关系是单向的。
@Entity
@Table(name = "role_assignments", uniqueConstraints = @UniqueConstraint(columnNames = {
"user_id", "organization_id" }))
public class GrantedRole extends DomainEntity implements GrantedAuthority {
public static enum Role {
ROLE_MODM_USER, ROLE_MODM_ORGADMIN, ROLE_MODM_ADMIN
}
private User user;
private Role role;
private Organization organization;
public static enum Role {
ROLE_MODM_USER, ROLE_MODM_ORGADMIN, ROLE_MODM_ADMIN
}
@ManyToOne
@NotNull
public User getUser() {
return user;
}
@NotNull
@Enumerated(EnumType.STRING)
public Role getRole() {
return role;
}
@ManyToOne
public Organization getOrganization() {
return organization;
}
// Some setters
}
@Entity …Run Code Online (Sandbox Code Playgroud) java ×2
jpa ×2
hibernate ×1
inner-join ×1
ios ×1
memory ×1
mongodb ×1
objective-c ×1
one-to-many ×1
rncryptor ×1
spring-boot ×1