Browse Source
[3.3.3] dao sql tests: run on postgresql container with in-memory disk using testcontainers jdbc (jdbc:tc:postgresql:12.8)pull/5744/head
committed by
GitHub
35 changed files with 296 additions and 484 deletions
@ -0,0 +1,42 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.controller; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.junit.After; |
|||
import org.junit.Before; |
|||
import org.thingsboard.server.queue.memory.InMemoryStorage; |
|||
|
|||
@Slf4j |
|||
public abstract class AbstractInMemoryStorageTest { |
|||
|
|||
@Before |
|||
public void setUpInMemoryStorage() { |
|||
log.info("set up InMemoryStorage"); |
|||
cleanupInMemStorage(); |
|||
} |
|||
|
|||
@After |
|||
public void tearDownInMemoryStorage() { |
|||
log.info("tear down InMemoryStorage"); |
|||
cleanupInMemStorage(); |
|||
} |
|||
|
|||
public static void cleanupInMemStorage() { |
|||
InMemoryStorage.getInstance().cleanup(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.queue.memory; |
|||
|
|||
import org.junit.After; |
|||
import org.junit.Before; |
|||
import org.junit.Test; |
|||
import org.thingsboard.server.queue.TbQueueMsg; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
import static org.mockito.Mockito.mock; |
|||
|
|||
public class InMemoryStorageTest { |
|||
|
|||
InMemoryStorage storage = InMemoryStorage.getInstance(); |
|||
|
|||
@Before |
|||
public void setUp() { |
|||
storage.cleanup(); |
|||
} |
|||
|
|||
@After |
|||
public void tearDown() { |
|||
storage.cleanup(); |
|||
} |
|||
|
|||
@Test |
|||
public void givenStorage_whenGetLagTotal_thenReturnInteger() throws InterruptedException { |
|||
assertThat(storage.getLagTotal()).isEqualTo(0); |
|||
storage.put("main", mock(TbQueueMsg.class)); |
|||
assertThat(storage.getLagTotal()).isEqualTo(1); |
|||
storage.put("main", mock(TbQueueMsg.class)); |
|||
assertThat(storage.getLagTotal()).isEqualTo(2); |
|||
storage.put("hp", mock(TbQueueMsg.class)); |
|||
assertThat(storage.getLagTotal()).isEqualTo(3); |
|||
storage.get("main"); |
|||
assertThat(storage.getLagTotal()).isEqualTo(1); |
|||
storage.cleanup(); |
|||
assertThat(storage.getLagTotal()).isEqualTo(0); |
|||
} |
|||
} |
|||
@ -1,30 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao; |
|||
|
|||
import org.junit.extensions.cpsuite.ClasspathSuite; |
|||
import org.junit.extensions.cpsuite.ClasspathSuite.ClassnameFilters; |
|||
import org.junit.runner.RunWith; |
|||
|
|||
@RunWith(ClasspathSuite.class) |
|||
@ClassnameFilters({ |
|||
"org.thingsboard.server.dao.service.psql.*SqlTest", |
|||
"org.thingsboard.server.dao.service.attributes.psql.*SqlTest", |
|||
"org.thingsboard.server.dao.service.event.psql.*SqlTest", |
|||
"org.thingsboard.server.dao.service.timeseries.psql.*SqlTest" |
|||
}) |
|||
public class PostgreSqlDaoServiceTestSuite { |
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.service; |
|||
|
|||
import org.springframework.test.context.TestPropertySource; |
|||
|
|||
import java.lang.annotation.Documented; |
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Inherited; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
@Target(ElementType.TYPE) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Inherited |
|||
@Documented |
|||
@TestPropertySource(locations = {"classpath:application-test.properties", "classpath:psql-test.properties"}) |
|||
public @interface DaoPostgreSqlTest { |
|||
} |
|||
@ -1,47 +0,0 @@ |
|||
database.ts.type=sql |
|||
database.ts_latest.type=sql |
|||
sql.ts_inserts_executor_type=fixed |
|||
sql.ts_inserts_fixed_thread_pool_size=200 |
|||
sql.ts_key_value_partitioning=MONTHS |
|||
# |
|||
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true |
|||
spring.jpa.properties.hibernate.order_by.default_null_ordering=last |
|||
spring.jpa.properties.hibernate.jdbc.log.warnings=false |
|||
spring.jpa.show-sql=false |
|||
spring.jpa.hibernate.ddl-auto=none |
|||
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect |
|||
spring.datasource.username=postgres |
|||
spring.datasource.password=postgres |
|||
spring.datasource.url=jdbc:tc:postgresql:12.8:///thingsboard?TC_DAEMON=true&TC_TMPFS=/testtmpfs:rw&?TC_INITFUNCTION=org.thingsboard.server.dao.PostgreSqlInitializer::initDb |
|||
spring.datasource.driverClassName=org.testcontainers.jdbc.ContainerDatabaseDriver |
|||
#org.postgresql.Driver |
|||
spring.datasource.hikari.maximumPoolSize=50 |
|||
service.type=monolith |
|||
#database.ts.type=timescale |
|||
#database.ts.type=sql |
|||
#database.entities.type=sql |
|||
# |
|||
#sql.ts_inserts_executor_type=fixed |
|||
#sql.ts_inserts_fixed_thread_pool_size=200 |
|||
#sql.ts_key_value_partitioning=MONTHS |
|||
# |
|||
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true |
|||
#spring.jpa.show-sql=false |
|||
#spring.jpa.hibernate.ddl-auto=none |
|||
#spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect |
|||
# |
|||
#spring.datasource.username=postgres |
|||
#spring.datasource.password=postgres |
|||
#spring.datasource.url=jdbc:postgresql://localhost:5432/sqltest |
|||
#spring.datasource.driverClassName=org.postgresql.Driver |
|||
#spring.datasource.hikari.maximumPoolSize = 50 |
|||
queue.core.pack-processing-timeout=3000 |
|||
queue.rule-engine.pack-processing-timeout=3000 |
|||
queue.rule-engine.queues[0].name=Main |
|||
queue.rule-engine.queues[0].topic=tb_rule_engine.main |
|||
queue.rule-engine.queues[0].poll-interval=25 |
|||
queue.rule-engine.queues[0].partitions=3 |
|||
queue.rule-engine.queues[0].pack-processing-timeout=3000 |
|||
queue.rule-engine.queues[0].processing-strategy.type=SKIP_ALL_FAILURES |
|||
queue.rule-engine.queues[0].submit-strategy.type=BURST |
|||
sql.log_entity_queries=true |
|||
Loading…
Reference in new issue