1)aws configure
2)aws configure list : will list config being used to connect to aws services. Credentials are present inside shared credentials file located in .aws/credentials file and other configs like region is present inside .aws/config
Hi All, This Blog is all about the various challenges and tasks we perform while coding.It will cover various updates related to Spring,Struts,Hibernate,JPA,Web Services,Javascript, Bootstrap,third party integration etc
1)aws configure
2)aws configure list : will list config being used to connect to aws services. Credentials are present inside shared credentials file located in .aws/credentials file and other configs like region is present inside .aws/config
Setup Pytest in Pycharm for running test cases
1)Install pytest package from python interpreter option by navigating to preferences ---->python interpreter
2)Create new run/debug configuration for test cases wherein following information need to be given:
2.1) Name of the run/debug give it as per your choice.
2.2) Target: This will the folder under which you want to run tests . It has different options like script, custom etc.
* Use script if want to execute all test cases under folder/project.
* Use custom if want to make dynamic file selection like I did by passing --tb=1 as argument . This will pick current file and run test cases inside that file.
3)Working directory: This is last and mandatory to specify where to pick files from.
4)Last change is make sure you are using pytest as test runner and it is selected in preferences-->Python Integrated Tools---->Testing--->Default test Runner --(pytest)
Below is step 2 configuration screenshot
1)Lambda expression/function: is an anonymous function that can be passed around where anonymous means that it does not have name .It is function as it is not associated with class like method. Passed around means it can passed as an argument to a method or can be stored in a variable.
Usage ::
Used to represent the instance of the functional interface.
syntax is as follows:
(a,b)->System.out.println(a+b);
Advantage ::
No boiler plate code for simple things.
2)Functional interface: is an interface which contains only one abstract method but can have any number of default methods.
@FunctionalInteface
public interface Predicate{
boolean test(T t);
}
@FunctionalInterface
public interface Consumer {
void accept(T t);
}
@FunctionalInterface
public interface Function{
public R apply(T t);
}
@FunctionalInterface
public interface Supplier{
public T get();
}
3)Default method inside Interface :
public interface MyInterface { // regular interface methods default void defaultMethod() { // default method implementation } }
In a typical design based on abstractions, where an interface has one or multiple implementations, if one or more methods are added to the interface, all the implementations will be forced to implement them too. Otherwise, the design will just break down.
Default interface methods are an efficient way to deal with this issue. They allow us to add new methods to an interface that are automatically available in the implementations. Therefore, we don't need to modify the implementing classes.
In this way, backward compatibility is neatly preserved without having to refactor the implementers.
what happens when a class implements several interfaces that define the same default methods.
In that case, the code simply won't compile, as there's a conflict caused by multiple interface inheritance (a.k.a the Diamond Problem).
To solve this ambiguity, we must explicitly provide an implementation for the methods by overriding the implementation in class.
@Override public String turnAlarmOn() { return Vehicle.super.turnAlarmOn(); } @Override public String turnAlarmOff() { return Vehicle.super.turnAlarmOff(); }
4)static method inside Interface
5)Predicate<T> : has test method returns boolean
6)Function <T,R> : has apply method return R type after applying some business logic.
7)Consumer<T> : has accept method and it does not return anything instead can be used for iteration.
8)Supplier< > : has get Method and it returns T type object.
9)Method reference and constructor reference by using :: (double colon ) operator.
10)Streams
11)Date & Time API (Joda API)
PermGen is memory area which was part of heap prior to Java 8. This is used to load class and method objects which means it was directly related to the number of classes objects being created. So when number of classes increases there objects can also increase and hence we use to face one issue java.lang.OutOfMemory error due to PermGen Size. We use to increase PermGen size using xx:MaxPermGen .
But there is new change in java 8 wherein this PermGen has been replaced by Metaspace which means there is no PermGen in java 8 onwards.
Old JVM memory consist of 1)Heap 2)Native memory
wherein Heap consists of
a)Old generation. b)New Generation. c)PermGen
New JVM memory consists of 1)Heap 2)Native memory
wherein Heap consists of
a)Old generation. b)New Generation
Native memory consists of
a)Metaspace
Now metaspace is controlled by the native memory which is dependent of the host .So in case many classes are loaded due to xyz reason it may happen that process size can increase immensely and by so entire server can crash not only application.
So for this we have new parameter using which we can we can limit size of metaspace given by xx::MaxMetaspaceSize.
Conclusion::
1)we need to monitor heap as well as process size now. Process size can be monitored using system utilities like top in unix/linux and Task Manager in windows.
2)Jmap can be used as follows: Jmap -permstat <PID>
3)No more PermGen space from java 8 onwards. Inclusion of metaspace.
3)QA should be made aware of this while doing testing.
1)Create Ec2 instance and get its key-pair for ssh to it .
ssh ec2user@17.38.292.1 -i ec2key.pem (Make sure key has right permission if not change it by command . chmod 400 ec2key.pem)
2)Once login can configure aws cli by running below command. Below command shall work in Amazon type Ec2.
aws configure (This works in amazon instance)
Prompt for below ::
Access key :
Secret access key:
Default region name: us-east-1
Output format: json
3)create dynamco db tables
a) After running AWS Configure, create a DynamoDB table using the following command:
aws dynamodb create-table --table-name ProductCatalog --attribute-definitions \
AttributeName=Id,AttributeType=N --key-schema \
AttributeName=Id,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
b) This is the command to populate the table:
**** (make sure items.json is located in your working directory) ****
aws dynamodb batch-write-item --request-items file://items.json
where items.json contains: {
"ProductCatalog": [{
"PutRequest": {
"Item": {
"Id": {
"N": "201"
},
"ProductCategory": {
"S": "Bicycle"
},
"Description": {
"S": "Womens Road Bike"
},
"BicycleType": {
"S": "Road"
},
"Brand": {
"S": "Raleigh"
},
"Price": {
"N": "399"
},
"Color": {
"S": "Red"
}
}
}
},
{
"PutRequest": {
"Item": {
"Id": {
"N": "403"
},
"ProductCategory": {
"S": "Helmet"
},
"Description": {
"S": "Womens Cycling Helmet"
},
"Size": {
"S": "Small"
},
"Price": {
"S": "99"
},
"Color": {
"S": "Black"
}
}
}
},
{
"PutRequest": {
"Item": {
"Id": {
"N": "411"
},
"ProductCategory": {
"S": "Book"
},
"Description": {
"S": "The Read Aloud Cloud"
},
"Author": {
"S": "Forrest Brazeal"
},
"Price": {
"N": "19.99"
},
"Format": {
"S": "Hardback"
}
}
}
},
{
"PutRequest": {
"Item": {
"Id": {
"N": "563"
},
"ProductCategory": {
"S": "Helmet"
},
"Description": {
"S": "Mens Cycling Helmet"
},
"Size": {
"S": "Small"
},
"Price": {
"N": "75"
},
"Color": {
"S": "Blue"
}
}
}
},
{
"PutRequest": {
"Item": {
"Id": {
"N": "543"
},
"ProductCategory": {
"S": "Helmet"
},
"Description": {
"S": "Womens Cycling Helmet"
},
"Size": {
"S": "Medium"
},
"Price": {
"N": "199"
},
"Color": {
"S": "Red"
}
}
}
},
{
"PutRequest": {
"Item": {
"Id": {
"N": "493"
},
"ProductCategory": {
"S": "Helmet"
},
"Description": {
"S": "Childs Cycling Helmet"
},
"Size": {
"S": "Small"
},
"Price": {
"N": "99"
},
"Color": {
"S": "Black"
}
}
}
},
{
"PutRequest": {
"Item": {
"Id": {
"N": "347"
},
"ProductCategory": {
"S": "Helmet"
},
"Description": {
"S": "Womens Cycling Helmet"
},
"Size": {
"S": "Small"
},
"Price": {
"N": "79"
},
"Color": {
"S": "Blue"
}
}
}
},
{
"PutRequest": {
"Item": {
"Id": {
"N": "467"
},
"ProductCategory": {
"S": "Bicycle"
},
"Description": {
"S": "Mens Road Bike"
},
"BicycleType": {
"S": "Road"
},
"Brand": {
"S": "Raleigh"
},
"Price": {
"N": "250"
},
"Color": {
"S": "Blue"
}
}
}
},
{
"PutRequest": {
"Item": {
"Id": {
"N": "566"
},
"ProductCategory": {
"S": "Bicycle"
},
"Description": {
"S": "Mens Mountain Bike"
},
"BicycleType": {
"S": "Mountain"
},
"Brand": {
"S": "Raleigh"
},
"Price": {
"N": "599"
},
"Color": {
"S": "Black"
}
}
}
}
]
}
Response:
{
"UnprocessedItems":{}
}
c) This is the command to query Dynamodb from EC2 command line - make sure the region is correct. You should be working in us-east-1.
aws dynamodb get-item --table-name ProductCatalog --region us-east-1 --key '{"Id": {"N":"403"}}'