-
Notifications
You must be signed in to change notification settings - Fork 256
Combinig cosmos db samples #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
d8411ee
2ad345c
5beab96
d5ef1b1
e14201f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.sample.cosmos; | ||
package spring.cloud.azure.starter.data.cosmos.sample; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -9,54 +9,40 @@ | |
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.util.Assert; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Optional; | ||
|
||
@SpringBootApplication | ||
public class CosmosSampleApplication implements CommandLineRunner { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(CosmosSampleApplication.class); | ||
public class CosmosdbSpringApplication implements CommandLineRunner { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CosmosdbSpringApplication.class); | ||
|
||
@Autowired | ||
private UserRepository repository; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(CosmosSampleApplication.class, args); | ||
SpringApplication.run(CosmosdbSpringApplication.class, args); | ||
} | ||
|
||
@Override | ||
public void run(String... var1) { | ||
this.repository.deleteAll().block(); | ||
this.repository.deleteAll(); | ||
LOGGER.info("Deleted all data in container."); | ||
|
||
final User testUser = new User("testId", "testFirstName", "testLastName", "test address line one"); | ||
|
||
// Save the User class to Azure Cosmos DB database. | ||
final Mono<User> saveUserMono = repository.save(testUser); | ||
|
||
final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName"); | ||
final User savedUser = repository.save(testUser); | ||
|
||
// Nothing happens until we subscribe to these Monos. | ||
// findById will not return the user as user is not present. | ||
final Mono<User> findByIdMono = repository.findById(testUser.getId()); | ||
final User findByIdUser = findByIdMono.block(); | ||
Assert.isNull(findByIdUser, "User must be null"); | ||
|
||
final User savedUser = saveUserMono.block(); | ||
Assert.state(savedUser != null, "Saved user must not be null"); | ||
Assert.state(savedUser.getFirstName().equals(testUser.getFirstName()), "Saved user first name doesn't match"); | ||
|
||
firstNameUserFlux.collectList().block(); | ||
|
||
final Optional<User> optionalUserResult = repository.findById(testUser.getId()).blockOptional(); | ||
final Optional<User> optionalUserResult = repository.findById(testUser.getEmail()); | ||
Assert.isTrue(optionalUserResult.isPresent(), "Cannot find user."); | ||
|
||
final User result = optionalUserResult.get(); | ||
Assert.state(result.getFirstName().equals(testUser.getFirstName()), "query result firstName doesn't match!"); | ||
Assert.state(result.getLastName().equals(testUser.getLastName()), "query result lastName doesn't match!"); | ||
|
||
LOGGER.info("findOne in User collection get result: {}", result.toString()); | ||
LOGGER.info("spring-cloud-azure-data-cosmos-sample successfully run."); | ||
LOGGER.info("spring-cloud-azure-data-cosmos-sample-aks successfully run."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was added accidentally when moving from aks sample. Removed. Thanks! |
||
} | ||
} | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks!