How to Use Swagger UI
for API Testing
What
Is Swagger?
Swagger (now
known as the OpenAPI Initiative,
under the structure of the Linux Foundation) is a framework for describing your
API by using a common language that is easy to read and understand for
developers and testers, even if they have weak source code knowledge. You can
think of it as a blueprint for a house. You can use whatever building materials
you like, but you can't step outside the parameters of the blueprint.
Swagger has certain benefits compared with other
frameworks, such as:
- It's
comprehensible for developers and non-developers. Product managers,
partners, and even potential clients can have input into the design of
your API because they can see it clearly mapped out in the friendly UI.
- It's
human-readable and machine-readable. This means
that not only can this be shared with your team internally, but the same
documentation can be used to automate API-dependent processes.
- It's
easily adjustable. This makes it great for testing and
debugging API problems.
What
Is Swagger UI?
Swagger UI, a part
of Swagger, is an open source tool that generates a web page that documents the
APIs generated by the Swagger specification. This UI presentation of the APIs
is user-friendly and easy to understand, with all the logical complexity kept
behind the screen. This enables developers to execute and monitor the API
requests they sent and the results they received, making it a great tool for
developers, testers, and end consumers to understand the endpoints they are
testing. Swagger UI represents APIs within the browser, so I find it more
intuitive than other tools such as Postman, SoapUI, and others.
When you open the webpage, the browser will load the webpage
from the web server, and trigger requests to the API server to get data from
the database. SwaggerUI is automatically generated from any API defined in the
OpenAPI Specification and can be viewed within a browser.
Adding
Swagger UI to Your API Testing Project
To add Swagger UI into our project, you need to add one more
dependency (if not already added) to the pom.xml file.
Then, go to the URL with SwaggerUI: http://<host>:<port>/swagger-ui.html
Testing
Your APIs With Swagger UI
We can also use Swagger UI for testing APIs online. Let's look
at an example. We will be using the sample http://petstore.swagger.io/
Importing
a Swagger Definition
The first thing we need to do is import our API platform into
Swagger UI.
A Swagger API platform could be either in YAML or JSON format.
In this case, we will use JSON.
Put the Swagger API URL into a blank field and click the Explore button. This
will list out all the endpoints below.
Authentication
When you first run your tests, they may fail due to HTTP request
requirements like auth, headers, or query parameters.
Expand
/auth
, click
the Try it out button
and enter your account information.
Next, press the execute button,
it will respond with a failed or passed result. In this
case, we get the passed result response, with response code 200.
Besides that, you can get more detailed information with
the request
url and curl
command commands. Take the token string and put it
in Authorize.
Currently, there are 2 ways to authorize:
- api_auth
(OAuth2, implicit)
- auth_token
(apiKey)
But, for now, Swagger UI only supports auth_token (apiKey)
Testing
the APIs Manually
After the authorization step, we are now ready to test the API.
Let's do an example.
First, make a GET request.
1. Expand GET carrier/{client_id}/invoice/list
2. Click Try
it out
3. Enter the information parameter likes,
client_id=2989
.
4. Click the Execute button
to show your results.
What is SonarQube?
• Sonar
is a web based code quality analysis tool for Maven based Java projects. It
covers a wide area of code quality check points which include: Architecture
& Design, Complexity, Duplications, Coding Rules, Potential Bugs, Unit Test
etc.
Why use SonarQube?
• Sonar
covers the 7 sections of code quality Architecture and Design
• Unit
tests
• Duplicated
code
• Potential
bugs
• Complex
code
• Coding
standards
• Comments
What is role of database in SonarQube?
• Sonar
uses a Derby or H2 as default database. When running Sonar, it says that these
databases may only be used for evaluation. We can change this default database
and use our custom DB.
How to create reports in SonarQube?
• To
create reports using SonarQubemvn clean install mvn sonar:sonar -Dsonar.issuesreport.html.enable=true
SonarQube?
• Sonar
is a web based code quality analysis tool for Maven based Java projects. It
covers a wide area of code quality check points which include: Architecture
& Design, Complexity, Duplications, Coding Rules, Potential Bugs, Unit Test
etc.
What is SonarQube?
• It
is an open source platform for Continuous Inspection of code quality.
What was the earlier name of SonarQube ?
• Sonar
Where does SonarQube help ?
• SonarQube
provide report on coding standard , unit test, duplicate code, code coverage,
potential bugs etc.
At which port sonar server is available by default ?
• 9000
Does SonarQube only analysis java code ?
• No
, SonarQube can analysis more than 20 languages.
In which language SonarQube is written ?
• java
What are the main components of SonarQube Platform ?
• SonarQube
plugin for languages
• SonarQube
Scanner
• SonarQube
Server
• SonarQube
Database
What is the use of SonarQube Database ?
• SonarQube
Database stores configuration of the SonarQube instance like security settings
and they also store project quality snapshot.
What is the use of SonarQube Scanners ?
• It
analyze projects on Continuous Integration Servers
Mention basic steps for SonarQube processing ?
• Developer
develops code and sends its code into repository system like SCM, git
• An
automatic build is fired in Continuous Integration Server and execution of
SonarQube Scanner happens for SonarQube analysis.
• Report
is sent to SonarQube Server for processing.
• SonarQube
Server processes the report and stores the analysis report results in the
SonarQube Database and displays the results in the UI
• Developers
review, comment, challenge their Issues to manage and reduce their Technical
Debt through the SonarQube UI.
#1 Question
Explain what is JUnit?
JUnit is a testing framework for unit testing. It uses Java as a programming platform, and
it is an Open Source Software managed by the JUnit.org community. It uses Java
Archive package file format during compilation. The entire package framework
resides under different names for different versions. For example, for JUnit
3.8, it is junit.framework package and for JUnit 4 and later, it is org.junit
package.
#2 Question
Mention what is the difference between JUnit and TestNG?
JUnit TestNG
In JUnit the naming convention for annotation is a bit complicated for,
e.g., “Before”, “After” and “Expected”.--------> In TestNG it is easier to understand annotations like
“BeforMethod”, “AfterMethod” and “ExpectedException”.
In JUnit, for a method declaration you have to follow a specific style like
using “@BeforeClass” and “@AfterClass”.----> In
TestNG, there is no restriction like you have to declare methods in a specific
format.
In JUnit method name constraint is present.---> In TestNG method name constraint is not present, and
you can determine any test method names.
JUnit framework does not have “Parameterized Test” or “Dependency Test”
features. TestNG use “dependOnMethods” to
implement the dependency testing.
In JUnit grouping of test cases are not available.-----> In TestNG, grouping of test cases is
available.
JUnit does not support parallel execution on Selenium test cases.----> In TestNG Parallel execution of Selenium test
cases are possible.
It cannot re-run the failed cases. ------>It
can rerun the failed tests.
0 Answer Suggest an edit
#3 Question
Mention different methods of exception handling in JUnit?
Exceptional or analogous conditions during program execution require
special processing methods and this exception handling process in a program
computation can be of many types. There are different methods of exception
handling in JUnit
Try catch idiom
With JUnit rule
With @Test annotation
With catch exception library
With customs annotation
0 Answer Suggest an edit
#4 Question
Explain who should use JUnit – a developer or tester? Why you use JUnit to
test your code?
JUnit is more often used by developers to implement unit tests in JAVA. It is designed for unit testing that is more
a coding process and not a testing process. However, many testers and QA
engineers use JUnit for unit testing.
JUnit is used because
It test early and does automate testing.
JUnit tests can be compiled with the build so that at unit level,
regression testing can be done.
It allows test code re-usage.
JUnit tests behave as a document for the unit tests when there is a
transfer.
0 Answer Suggest an edit
#5 Question
What are the important JUnit annotations?
The test runner is used to execute the test cases.
@Test: This is the test method to run first unless otherwise specified.
@BeforeClass: This is run once before any of the other test methods present
in the class.
@Before: This is run before @Test.
@After: As the name suggests, this is run after the @Test.
@AfterClass: This is run one after all of the tests in the class have been
run.
0 Answer Suggest an edit
#6 Question
What are the features of JUnit?
There are several features of JUnit such as:
Open source
Annotation support for test cases
Assertion support for checking the expected result
Test runner support to execute the test case
#7 Question
What are the useful JUnit extensions?
There are several JUnit extensions such as:
JWebUnit
XMLUnit
Cactus
MockObject
#8 Question
Explain what is Unit Test Case?
Unit Test Case is a part of the code that ensures that another part of the
code (method) behaves as expected. For each requirement, there must be at least
two test cases one negative test and one positive test.
#9 Question
Explain how you can write a simple JUnit test case?
The simplest way to write a JUnit test case is:
Determine a subclass of TestCase
To initialize object(s) under test, override the setup() method
To release object(s) under test override the teardown() method
Determine one or more public test XYZ() methods that exercise the objects
under test and assert expected results.
#10 Question
Explain what is meant by ignoring test in JUnit?
When your code is not ready, and it would fail if executed then you can use
@Ignore annotation.
It will not execute a test method annotated with @Ignore
It will not execute any of the test methods of test class if it is
annotated with @Ignore
#11 Question
What are the top advantages of writing unit tests?
The advantages of writing unit tests include Design testability, Code
testability and Code maintainability as good unit tests enforces Object
Oriented principles such as Single Responsibility etc. which enables people to
avoid code smells such as long classes, long methods, large conditionals etc.
#12 Question
How is code cyclomatic complexity related to unit tests?
As code cyclomatic complexity is determined based on number of decision
points within the code and hence execution paths, higher cyclomatic complexity
makes it difficult to attain achieve test/code coverage.
#13 Question
What is mocking and stubbing? Did you use any mocking framework?
Mocking is a feature where an object mimics like a real object. Stubbing
are codes that are responsible for taking place of another component.
There are various different Java mocking framework such as Mockito,
EasyMock etc.
#14 Question
What is unit testing method-naming convention that you follow?
The convention you follow should have every information required by the
method name in a structured manner. Unit tests name should act like the
documentation giving a clear idea of what functionality is tested. There are
various techniques that could be used to name unit tests. Some of them are the following:
Given… When… Then… Should… etc.
#15 Question
What do following JUnit test annotations mean?
Use of annotations reduces coding and extra burden from the tester.
Following is a list of frequently used JUnit 4 annotations: @Test (@Test
identifies a test method)
@Before (Ans: @Before method will execute before every JUnit4 test)@After
(Ans: @After method will execute after every JUnit4 test)@BeforeClass (Ans:
@BeforeClass method will be executed before the JUnit test for a Class
starts)@AfterClass (Ans: @AfterClass method will be executed after the JUnit
test for a Class is completed)@Ignore (@Ignore method will not be executed
JSON
Interview Questions And Answers
JSON Interview Questions # 1) What does JSON stand for?
Answer) JSON stands for “JavaScript Object
Notation”.
JSON Interview Questions # 2) What is JSON?
Answer) JSON is
a lightweight data-interchange format. It is easy for humans to read and write.
It is easy for machines to parse and generate. It is based on a subset of the
JavaScript Programming Language, Standard ECMA.
JSON Interview Questions # 3) What programming languages
supported by JSON?
Answer)
JSON is a text format that is completely language independent but uses
conventions that are familiar to programmers of the C-family of languages,
including C, C++, C#, Java, JavaScript, Perl, Python, and many others.
JSON Interview Questions # 4) Is JSON is a language?
Answer)
JSON is a data format. It could be classified as a language, but not a
programming language. Its relationship to JavaScript is that it shares its
syntax (more or less) with a subset of JavaScript literals.
JSON Interview Questions # 5) What are the properties of JSON?
Answer)
These properties make JSON an ideal data-interchange language.
JSON is
built on two structures:
A
collection of name/value pairs. In various languages, this is realized as an object,
record, struct, dictionary, hash table, keyed list, or associative array.
An
ordered list of values. In most languages, this is realized as an array,
vector, list, or sequence.
These
are universal data structures. Virtually all modern programming languages
support them in one form or another. It makes sense that a data format that is
interchangeable with programming languages also be based on these structures.
JSON
Interview Questions For Freshers
JSON Interview Questions # 6) Why do we use JSON?
Answer)
The JSON format is often used for serializing and transmitting structured data
over a network connection. It is used primarily to transmit data between a
server and web application, serving as an alternative to XML.
JSON Interview Questions # 7) What is JSON data?
Answer)
JSON, or JavaScript Object Notation, is a minimal, readable format for
structuring data. In JSON data is nothing but a information. It is used
primarily to transmit data between a server and web application, as an
alternative to XML.
JSON Interview Questions # 8) What is the difference between XML
and JSON?
Answer)
The fundamental difference, which no other answer seems to have mentioned, is
that XML is a markup language (as it actually says in its name), whereas JSON
is a way of representing objects (as also noted in its name). This is what
makes markup languages so useful for representing documents.
JSON Interview Questions # 9) Why JSON format is better than
XML?
Answer)
JSON and XML used different formats. When compared both JSON is easy to write
and use it applications then XML. The XML format can also be determined by the
XML DTD or XML Schema (XSL) and can be tested.
The
JSON a data-exchange format which is getting more popular as the JavaScript
applications possible format. Basically this is an object notation array. JSON
has a very simple syntax so can be easily learned.
JSON Interview Questions # 10) Is JSON markup language?
Answer)
JSON is like XML in that it is used to structure data in a text format and is
commonly used to exchange data over the Internet. JSON is not a markup
language. JSON (JavaScript Object Notation) is a lightweight data-interchange
format. It is easy for humans to read and write.
Top
JSON Interview Questions
11) What is JSON Text?
Answer)
A JSON text is a sequence of tokens formed from Unicode code points that
conforms to the JSON value grammar. The set of tokens includes six structural
tokens, strings, numbers, and three literal name tokens.
The six
structural tokens:
[ U+005B left square bracket
{ U+007B left curly bracket
] U+005D right square bracket
} U+007D right curly bracket
: U+003A colon
, U+002C comma
[ U+005B left square bracket
{ U+007B left curly bracket
] U+005D right square bracket
} U+007D right curly bracket
: U+003A colon
, U+002C comma
These
are the three literal name tokens:
true U+0074 U+0072 U+0075 U+0065
false U+0066 U+0061 U+006C U+0073 U+0065
null U+006E U+0075 U+006C U+006C
true U+0074 U+0072 U+0075 U+0065
false U+0066 U+0061 U+006C U+0073 U+0065
null U+006E U+0075 U+006C U+006C
Insignificant
whitespace is allowed before or after any token. Whitespace is any sequence of
one or more of the following code points: character tabulation (U+0009), line
feed (U+000A), carriage return (U+000D), and space (U+0020). Whitespace is not
allowed within any token, except that space is allowed in strings.
JSON Interview Questions # 12) What is JSON Value?
Answer)
A JSON value can be an object, array, number, string, true, false, or null.
13) What is JSON Syntax?
A) JSON
syntax is derived from JavaScript object notation syntax. Data is in name/value
pairs. Data is separated by commas. Curly braces hold objects. Square brackets
hold arrays.
JSON
Interview Questions # 14) What is JSON Value?
Answer)
In JSON, value holds some data. A value can be a string in double quotes, or a
number, or true or false or null, or an object or an array. These structures
can be nested.
Values
in JSON must be one of the following data types:
·
a string
·
a number
·
an object (JSON object)
·
an array
·
a boolean
·
null
15) What is JSON Array?
Answer)
An array structure is a pair of square bracket tokens surrounding zero or more
values. An array is an ordered collection of values. An array begins with [
(left bracket) and ends with ] (right bracket). Values are separated by ,
(comma).
The
values are separated by commas. The JSON syntax does not define any specific
meaning to the ordering of the values. However, the JSON array structure is
often used in situations where there is some semantics to the ordering.
Interview
Quetions And Answers on JSON
JSON Interview Questions # 16) What is Number in JSON?
Answer)
JSON Numbers – A number is very much like a C or Java number, except that the
octal and hexadecimal formats are not used. A number is a sequence of decimal
digits with no superfluous leading zero.
It may
have a preceding minus sign (U+002D). It may have a fractional part prefixed by
a decimal point (U+002E). It may have an exponent, prefixed by e (U+0065) or E
(U+0045) and optionally + (U+002B) or – (U+002D). The digits are the code
points U+0030 through U+0039.
Numeric
values that cannot be represented as sequences of digits (such as Infinity and
NaN) are not permitted.
17) What is JSON String?
Answer)
A string is a sequence of zero or more Unicode characters, wrapped in double
quotes, using backslash escapes. A character is represented as a single
character string. A string is very much like a C or Java string.
A
string is a sequence of Unicode code points wrapped with quotation marks
(U+0022). All code points may be placed within the quotation marks except for
the code points that must be escaped: quotation mark (U+0022), reverse solidus
(U+005C), and the control characters U+0000 to U+001F. There are two-character
escape sequence representations of some characters.
\”
represents the quotation mark character (U+0022).
\\ represents the reverse solidus character (U+005C).
\/ represents the solidus character (U+002F).
\b represents the backspace character (U+0008).
\f represents the form feed character (U+000C).
\n represents the line feed character (U+000A).
\r represents the carriage return character (U+000D).
\t represents the character tabulation character (U+0009).
\\ represents the reverse solidus character (U+005C).
\/ represents the solidus character (U+002F).
\b represents the backspace character (U+0008).
\f represents the form feed character (U+000C).
\n represents the line feed character (U+000A).
\r represents the carriage return character (U+000D).
\t represents the character tabulation character (U+0009).
JSON Interview Questions # 18) What is JSON object?
Answer)
An object is an unordered set of name/value pairs. An object begins with {
(left brace) and ends with } (right brace). Each name is followed by : (colon)
and the name/value pairs are separated by , (comma).
19) What is JSON RPA Java?
Answer)
JSON-RPC is a simple remote procedure call protocol similar to XML-RPC although
it uses the lightweight JSON format instead of XML (so it is much faster).
JSON Interview Questions # 20) What is a JSON parser?
Answer)
JSON parser to parse JSON object and MAINTAIN comments. By using JSON, when
receiving data from a web server, the data should be always in a string format.
We use JSON.parse() to parse the data and it becomes a JavaScript object.
The
JSON.parse() method parses a JSON string, constructing the JavaScript value or
object described by the string. An optional reviver function can be provided to
perform a transformation on the resulting object before it is returned.
Advanced
JSON Interview Questions
21) Which browser provides native JSON support?
Answer)
All modern browsers support native JSON encoding/decoding (Internet Explorer 8+,
Firefox 3.1+, Safari 4+, and Chrome 3+). Basically, JSON.parse(str) will parse
the JSON string in str and return an object, and JSON.stringify(obj) will
return the JSON representation of the object obj.
JSON Interview Questions # 22) What is the difference between
JSON parse and JSON Stringify?
Answer)
JSON.stringify() is to create a JSON string out of an object/array. They are
the inverse of each other. JSON.stringify() serializes a JS object into a JSON
string, whereas JSON.parse() will deserialize a JSON string into a JS object.
23) What is the MIME type of JSON?
Answer)
The MIME media type for JSON text is application/json . The default encoding is
UTF-8.
JSON Interview Questions # 24) What is the use of JSON
Stringify?
Answer)
The JSON.stringify() method converts a JavaScript value to a JSON string,
optionally replacing values if a replacer function is specified, or optionally
including only the specified properties if a replacer array is specified.
25) What does JSON parse do?
Answer)
The JSON.parse() method parses a JSON string, constructing the JavaScript value
or object described by the string. An optional reviver function can be provided
to perform a transformation on the resulting object before it is returned.
JSON Interview Questions # 26) What is serialization in
Javascript?
Answer)
The serialize() method creates a URL encoded text string by serializing form
values. You can select one or more form elements (like input and/or text area),
or the form element itself. The serialized values can be used in the URL query
string when making an AJAX request.
27) What is Polyfill?
Answer)
The JSON object is not supported in older browsers. We can work around this by
inserting a piece of code at the beginning of your scripts, allowing use of
JSON object in implementations which do not natively support it (like Internet
Explorer 6) is called Polyfill.
JSON Interview Questions # 28) What is toJSON() method in JOSN?
Answer)
The toJSON() method returns a string representation of the Date object.
29) What is JSONP?
Answer)
JSONP stands for JSON with Padding. JSONP is a method for sending JSON data
without worrying about cross-domain issues. JSONP does not use the
XMLHttpRequest object. JSONP uses the <script> tag instead.
JSON Interview Questions # 30) What is the difference between
JSON and JSONP?
Answer)
JSONP is a simple way to overcome browser restrictions when sending JSON
responses from different domains from the client. But the practical
implementation of the approach involves subtle differences that are often not
explained clearly. Here is a simple tutorial that shows JSON and JSONP side by
side.
JSON
Interview Questions For Experienced
31) What is serialization and deserialization in JSON?
Answer)
JSON is a format that encodes objects in a string. Serialization means to
convert an object into that string, and deserialization is its inverse
operation. When transmitting data or storing them in a file, the data are
required to be byte strings, but complex objects are seldom in this format.
JSON Interview Questions # 32) What is serialization of
an object?
Answer)
To serialize an object means to convert its state to a byte stream so that the
byte stream can be reverted back into a copy of the object.
33) What is the use of JSON in Java?
Answer)
The Java API for JSON Processing provides portable APIs to parse, generate,
transform, and query JSON. JSON (JavaScript Object Notation) is a lightweight,
text-based, language-independent data exchange format that is easy for humans
and machines to read and write.
JSON Interview Questions # 34) Why do we use JSON in PHP?
Answer)
A common use of JSON is to read data from a web server, and display the data in
a web page. This chapter will teach you how to exchange JSON data between the
client and a PHP server.
35) What is JSON Formatter?
Answer)
The JSON Formatter & Validator helps debugging JSON data by formatting and
validating JSON data so that it can easily be read by human beings.
JSON Interview Questions # 36) What is JSON Viewer?
Answer)
JSON Viewer – Convert JSON Strings to a Friendly Readable Format.
37) What is JSON Validator?
Answer)
The JSON Validator helps debugging JSON data by formatting and validating JSON
data so that it can easily be read by human beings.
JSON Interview Questions # 38) Why do we use JSON in Android?
JSON
stands for JavaScript Object Notation.It is an independent data exchange format
and is the best alternative for XML.
Android
provides four different classes to manipulate JSON data. These classes are
JSONArray,JSONObject,JSONStringer and JSONTokenizer.
39) Why do we use JSON in Python?
Answer)
Python programming language is used to encode and decode JSON objects.
Python
encode() function encodes the Python object into a JSON string representation.
Python
decode() function decodes a JSON-encoded string into a Python object.
JSON
Interview Questions & Answers
JSON Interview Questions # 40) What is JSON in JavaScript?
Answer)
JSON is derived from the JavaScript programming language, it is a natural
choice to use as a data format in JavaScript. JSON, short for JavaScript Object
Notation.
41) What is JSON Schema?
Answer)
JSON Schema is a specification for JSON based format for defining the structure
of JSON data.
JSON Interview Questions # 42) What are the advantages of JOSN?
Answer)
·
It is used while writing JavaScript based applications that
includes browser extensions and websites.
·
JSON format is used for serializing and transmitting structured
data over network connection.
·
It is primarily used to transmit data between a server and web
applications.
·
Web services and APIs use JSON format to provide public data.
·
It can be used with modern programming languages.
43) Can you write an example code in JSON?
Answer)
The following example shows how to use JSON to store information related to
books based on their topic and edition.
{
"book":
[
{
"id":"01",
"language":
"Java",
"edition":
"third",
"author":
"Herbert Schildt"
},
{
"id":"07",
"language":
"C++",
"edition":
"second"
"author":
"E.Balagurusamy"
}
]
}
What is RabbitMQ ?
A:RabbitMQ is an open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP). The RabbitMQ server is written in the Erlang programming language and is built on the Open Telecom Platform framework for clustering and failover.
Q: What is an exchange in RabbitMQ?
A: An exchange accepts messages from the producer application and routes them to message queues with help of header attributes, bindings, and routing keys. A binding is a "link" that you set up to bind a queue to an exchange.
A:RabbitMQ is an open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP). The RabbitMQ server is written in the Erlang programming language and is built on the Open Telecom Platform framework for clustering and failover.
Q: What is an exchange in RabbitMQ?
A: An exchange accepts messages from the producer application and routes them to message queues with help of header attributes, bindings, and routing keys. A binding is a "link" that you set up to bind a queue to an exchange.
Q: What is
routing key in RabbitMQ?
A:
A:
A: Erlang is a general-purpose, concurrent, functional programming language, as well as a garbage-collected runtime system. The RabbitMQ server is written in the Erlang programming language and is built on the Open Telecom Platform framework for clustering and failover. Since RabbitMQ is built on top of Erlang, we will first need to install Erlang beforing installing RabbitMQ
Q: How to
install RabbitMQ?
A:
Install RabbitMQ
on WindowsA:
Q: How to integrate RabbitMQ with Spring Boot?
A: Spring Boot + RabbitMQ Example
What is RabbitMQ ?
RabbitMQ is message
broker that accepts message sent by producer and accepts as receiver .
What is Exchange in RabbitMQ ?
Exchange is
responsible to route the message to different queue.Producer does not send
message to queue directly.It sends it to exchange which routes it to queues
with the help of binding and keys.
What are the type of Exchange in RabbitMQ ?
RabbitMQ have four types of Exchanges.
·
Direct
·
Topic
·
Fanout
·
Headers
What is fanout Exchange in RabbitMQ ?
Fanout exchange routes
the messages to all of the queues that are bound to it.
What is headers Exchange in RabbitMQ ?
Headers exchange uses
message header to route message.
What is direct Exchange in RabbitMQ ?
It delivers message to
queue whose binding key exactly matches to message routing key.
What is binding in RabbitMQ ?
It is a link between
queue and exchange.
What is routing key in RabbitMQ ?
Routing key is a key
that exchange looks to find the the binding queue.
What is GIT?
GIT
is a distributed version control system and source code management (SCM) system
with an emphasis to handle small and large projects with speed and efficiency.
What is a repository in GIT?
A
repository contains a directory named .git, where git keeps all of its metadata
for the repository. The content of the .git directory are private to git.
Git commands
git
config
git
init
git
clone
git
add
git
commit
git
diff
git
reset
git
status
git
rm
git
log
git
show
git
tag
git
branch
git
checkout
git
merge
git
remote
git
push
git
pull
git
stash
git config
Usage: git
config –global user.name “[name]”
Usage: git
config –global user.email “[email address]”
This
command sets the author name and email address respectively to be used with
your commits.
git init
Usage: git
init [repository name]
This
command is used to start a new repository.
git clone
Usage: git
clone [url]
This
command is used to obtain a repository from an existing URL.
git add
Usage: git
add [file]
This
command adds a file to the staging area.
Usage: git
add *
This
command adds one or more to the staging area.
git commit
Usage: git
commit -m “[ Type in the commit message]”
This
command records or snapshots the file permanently in the version history.
Usage: git
commit -a
This
command commits any files you’ve added with the git add command and also
commits any files you’ve changed since then.
git diff
Usage: git
diff
This
command shows the file differences which are not yet staged.
Usage:
git diff –staged
This
command shows the differences between the files in the staging area and the
latest version present.
Usage: git
diff [first branch] [second branch]
This
command shows the differences between the two branches mentioned.
git reset
Usage: git
reset [file]
This
command unstages the file, but it preserves the file contents.
Usage: git
reset [commit]
This
command undoes all the commits after the specified commit and preserves the
changes locally.
Usage: git
reset –hard [commit] This command discards all history and goes back
to the specified commit.
git status
Usage: git
status
This
command lists all the files that have to be committed.
git rm
Usage: git
rm [file]
This
command deletes the file from your working directory and stages the deletion.
git log
Usage: git
log
This
command is used to list the version history for the current branch.
Usage: git
log –follow[file]
This
command lists version history for a file, including the renaming of files also.
git show
Usage: git
show [commit]
This
command shows the metadata and content changes of the specified commit.
git tag
Usage: git
tag [commit ID]
This
command is used to give tags to the specified commit.
git branch
Usage: git
branch
This
command lists all the local branches in the current repository.
Usage: git
branch [branch name]
This
command creates a new branch.
Usage: git
branch -d [branch name]
This
command deletes the feature branch.
git checkout
Usage: git
checkout [branch name]
This
command is used to switch from one branch to another.
Usage: git
checkout -b [branch name]
This
command creates a new branch and also switches to it.
git merge
Usage: git
merge [branch name]
This
command merges the specified branch’s history into the current branch.
git remote
Usage: git
remote add [variable name] [Remote Server Link]
This
command is used to connect your local repository to the remote server.
git push
Usage: git
push [variable name] master
This
command sends the committed changes of master branch to your remote repository.
Usage: git
push [variable name] [branch]
This
command sends the branch commits to your remote repository.
Usage: git
push –all [variable name]
This
command pushes all branches to your remote repository.
Usage: git
push [variable name] :[branch name]
This
command deletes a branch on your remote repository.
git pull
Usage: git
pull [Repository Link]
This
command fetches and merges changes on the remote server to your working
directory.
git stash
Usage: git
stash save
This
command temporarily stores all the modified tracked files.
Usage: git
stash pop
This
command restores the most recently stashed files.
Usage: git
stash list
This
command lists all stashed changesets.
Usage: git
stash drop
This
command discards the most recently stashed changeset.
What is Apache Kafka?
Apache
Kafka is a distributed publish-subscribe messaging system. It is a scalable,
fault-tolerant, publish-subscribe messaging system which enables us to build distributed
applications. It is an Apache Top Level project. Kafka is suitable for both
offline and online message consumption.
What are the advantages of using Apache Kafka?
The
Advantages of using Apache Kafka are as follows-High Throughput-
The design of Kafka enables the platform to process messages at very fast speed. The processing rates in Kafka can exceed beyond 100k/seconds. The data is processed in a partitioned and ordered fashion.
The design of Kafka enables the platform to process messages at very fast speed. The processing rates in Kafka can exceed beyond 100k/seconds. The data is processed in a partitioned and ordered fashion.
Scalability-
The scalability can be achieved in Kafka at various levels. Multiple producers can write to the same topic. Topics can be partitioned. Consumers can be grouped to consume individual partitions.
The scalability can be achieved in Kafka at various levels. Multiple producers can write to the same topic. Topics can be partitioned. Consumers can be grouped to consume individual partitions.
Fault
Tolerance-
Kafka is a distributed architecture which means there are several nodes running together to serve the cluster. Topics inside Kafka are replicated. Users can choose the number of replicas for each topic to be safe in case of a node failure. Node failure in cluster won’t impact. Integration with Zookeeper provides producers and consumers accurate information about the cluster. Internally each topic has its own leader which takes care of the writes. Failure of node ensures new leader election.
Kafka is a distributed architecture which means there are several nodes running together to serve the cluster. Topics inside Kafka are replicated. Users can choose the number of replicas for each topic to be safe in case of a node failure. Node failure in cluster won’t impact. Integration with Zookeeper provides producers and consumers accurate information about the cluster. Internally each topic has its own leader which takes care of the writes. Failure of node ensures new leader election.
Durability-
Kafka offers data durability as well. The message written in Kafka can be persisted. The persistence can be configured. This ensures re-processing, if required, can be performed.
Kafka offers data durability as well. The message written in Kafka can be persisted. The persistence can be configured. This ensures re-processing, if required, can be performed.
List the various components in Kafka.
The
four major components of Kafka are:
Topic
– a stream of messages belonging to the same type
Producer
– that can publish messages to a topic
Brokers
– a set of servers where the publishes messages are stored
Consumer
– that subscribes to various topics and pulls data from the brokers.
What role ZooKeeper plays in a cluster of Kafka?
Kafka
is an open source system and also a distributed system is built to use
Zookeeper. The basic responsibility of Zookeeper is to build coordination
between different nodes in a cluster. Since Zookeeper works as periodically
commit offset so that if any node fails, it will be used to recover from
previously committed to offset.
The
ZooKeeper is also responsible for configuration management, leader detection, detecting
if any node leaves or joins the cluster, synchronization, etc.
Can Kafka be utilized without Zookeeper?
It
is impossible to use Kafka
without Zookeeper because it is not feasible to go around Zookeeper
and attach in a straight line to the server. If the Zookeeper is down for a
number of causes, then we will not be able to serve any customer demand.
Elaborate Kafka architecture.
A
cluster contains multiple brokers since it is a distributed system. Topic in
the system will get divided into multiple partitions and each broker store one
or more of those partitions so that multiple producers and consumers can
publish and retrieve messages at the same time.
How to start a Kafka server?
Given
that Kafka exercises Zookeeper, we have to start the Zookeeper’s server.
One
can use the convince script packaged with Kafka to get a crude but effective
single node Zookeeper instance>
bin/zookeeper-server-start.shconfig/zookeeper.properties Now the Kafka server
can start> bin/Kafka-server-start.shconfig/server.properties
What are consumers or users?
Kafka
provides single consumer abstractions that discover both queuing and publish-subscribe
Consumer Group. They tag themselves with a user group and every communication
available on a topic is distributed to one user case within every promising
user group. User instances are in disconnected process. We can determine the
messaging model of the consumer based on the consumer groups.
If
all consumer instances have the same consumer set, then this works like a
conventional queue adjusting load over the consumers.
If
all customer instances have dissimilar consumer groups, then this works like a
publish-subscribe and all messages are transmitted to all the consumers.
Why is Kafka technology
significant to use?
Kafka
being distributed publish-subscribe system has the advantages as below. Fast:
Kafka comprises of a broker and a single broker can serve thousands of clients
by handling megabytes of reads and writes per second. Scalable: facts are
partitioned and streamlined over a cluster of machines to enable large
information Durable: Messages are persistent and is replicated in the cluster
to prevent record loss Distributed by Design: It provides fault tolerance
guarantees and robust.
What is Kafka Logs?
An
important concept for Apache Kafka is “logâ€.
This is not related to application log or system log. This is a log of the
data. It creates a loose structure of the data which is consumed by Kafka. The notion
of “log†is an ordered, append-only
sequence of data. The data can be anything because for Kafka it will be just an
array of bytes.
When not to use Apache Kafka?
Kafka
doesn’t number the messages. It has a notion of offset inside the log which
identifies the messages.
Consumers
consume the data from topics but Kafka does not keep track of the message
consumption. Kafka does not know which consumer consumed which message from the
topic. The consumer or consumer group has to keep a track of the consumption.
There
are no random reads from Kafka. Consumer has to mention the offset for the
topic and Kafka starts serving the messages in order from the given offset.
Kafka
does not offer the ability to delete. The message stays via logs in Kafka till
it expires (until the retention time defined).
Explain the role of the offset.
Messages
contained in the partitions are assigned a unique ID number that is called
the offset. The role of the offset is to uniquely identify every message
within the partition.
What is a Consumer Group?
Consumer
Groups is a concept exclusive to Kafka. Every Kafka consumer group
consists of one or more consumers that jointly consume a set of subscribed
topics.
What is the role of the ZooKeeper?
Kafka
uses Zookeeper to store offsets of messages consumed for a specific topic and
partition by a specific Consumer Group.
Is it possible to use Kafka without
ZooKeeper?
No,
it is not possible to bypass Zookeeper and connect directly to the Kafka
server. If, for some reason, ZooKeeper is down, you cannot service any client
request.
Why are Replications critical in
Kafka?
Replication
ensures that published messages are not lost and can be consumed in the event
of any machine error, program error or frequent software upgrades.
What is the process for starting a
Kafka server?
Since
Kafka uses ZooKeeper, it is essential to initialize the ZooKeeper server, and
then fire up the Kafka server.
To
start the ZooKeeper server: > bin/zookeeper-server-start.sh
config/zookeeper.properties
Next,
to start the Kafka server: > bin/kafka-server-start.sh
config/server.properties
What is GIT?
GIT is a distributed version control system and source code management (SCM) system with an
emphasis to handle small and large projects with speed and efficiency.
2) What is a repository in GIT?
A repository contains a directory named .git, where git keeps all of its metadata for the repository.
The content of the .git directory are private to git.
3) What is the command you can use to write a commit message?
The command that is used to write a commit message is “git commit –a”. The –a on the command
line instructs git to commit the new content of all tracked files that have been modified. You can use
“git add<file>” before git commit –a if new files need to be committed for the first time.
4) What is the difference between GIT and SVN?
The difference between GIT and SVN is
a) Git is less preferred for handling extremely large files or frequently changing binary files while
SVN can handle multiple projects stored in the same repository.
b) GIT does not support ‘commits’ across multiple branches or tags. Subversion allows the
creation of folders at any location in the repository layout.
c) Gits are unchangeable, while Subversion allows committers to treat a tag as a branch and to
create multiple revisions under a tag root.
5) What are the advantages of using GIT?
a) Data redundancy and replication
b) High availability
c) Only one.git directory per repository
d) Superior disk utilization and network performance
e) Collaboration friendly
f) Any sort of projects can use GIT
6) What language is used in GIT?
GIT is fast, and ‘C’ language makes this possible by reducing the overhead of runtimes associated
with higher languages.
7) What is the function of ‘GIT PUSH’ in GIT?
‘GIT PUSH’ updates remote refs along with associated objects.
8) Why GIT better than Subversion?
GIT is an open source version control system; it will allow you to run ‘versions’ of a project, which
show the changes that were made to the code overtime also it allows you keep the backtrack if
necessary and undo those changes. Multiple developers can checkout, and upload changes and each
change can then be attributed to a specific developer.
9) What is “Staging Area” or “Index” in GIT?
Before completing the commits, it can be formatted and reviewed in an intermediate area known as
‘Staging Area’ or ‘Index’.
10) What is GIT stash?
GIT stash takes the current state of the working directory and index and puts in on the stack for later
and gives you back a clean working directory. So in case if you are in the middle of something and
need to jump over to the other job, and at the same time you don’t want to lose your current edits
then you can use GIT stash.
11) What is GIT stash drop?
When you are done with the stashed item or want to remove it from the list, run the git ‘stash drop’
command. It will remove the last added stash item by default, and it can also remove a specific item
if you include as an argument.
12) How will you know in GIT if a branch has been already merged into master?
Git branch—merged lists the branches that have been merged into the current branch
Git branch—-no merged lists the branches that have not been merged
13) What is the function of git clone?
The git clone command creates a copy of an existing Git repository. To get the copy of a central
repository, ‘cloning’ is the most common way used by programmers.
14) What is the function of ‘git config’?
The ‘git config’ command is a convenient way to set configuration options for your Git installation.
Behaviour of a repository, user info, preferences etc. can be defined through this command.
15) What does commit object contain?
a) A set of files, representing the state of a project at a given point of time
b) Reference to parent commit objects
c) An SHAI name, a 40 character string that uniquely identifies the commit object.
16) How can you create a repository in Git?
In Git, to create a repository, create a directory for the project if it does not exist, and then run
command “git init”. By running this command .git directory will be created in the project directory,
the directory does not need to be empty.
17) What is ‘head’ in git and how many heads can be created in a repository?
A ‘head’ is simply a reference to a commit object. In every repository, there is a default head referred
as “Master”. A repository can contain any number of heads.
18) What is the purpose of branching in GIT?
The purpose of branching in GIT is that you can create your own branch and jump between those
branches. It will allow you to go to your previous work keeping your recent work intact.
19) What is the common branching pattern in GIT?
The common way of creating branch in GIT is to maintain one as “Main“
branch and create another branch to implement new features. This pattern is particularly useful when
there are multiple developers working on a single project.
20) How can you bring a new feature in the main branch?
To bring a new feature in the main branch, you can use a command “git merge” or “git pull
command”.
21) What is a ‘conflict’ in git?
A ‘conflict’ arises when the commit that has to be merged has some change in one place, and the
current commit also has a change at the same place. Git will not be able to predict which change
should take precedence.
22) How can conflict in git resolved?
To resolve the conflict in git, edit the files to fix the conflicting changes and then add the resolved
files by running “git add” after that to commit the repaired merge, run “git commit”. Git remembers
that you are in the middle of a merger, so it sets the parents of the commit correctly.
23) To delete a branch what is the command that is used?
Once your development branch is merged into the main branch, you don’t need
development branch. To delete a branch use, the command “git branch –d [head]”.
24) What is another option for merging in git?
“Rebasing” is an alternative to merging in git.
25) What is the syntax for “Rebasing” in Git?
The syntax used for rebase is “git rebase [new-commit] “
26) What is the difference between ‘git remote’ and ‘git clone’?
‘git remote add’ just creates an entry in your git config that specifies a name for a particular URL.
While, ‘git clone’ creates a new git repository by copying and existing one located at the URI.
27) What is GIT version control?
With the help of GIT version control, you can track the history of a collection of files and includes the
functionality to revert the collection of files to another version. Each version captures a snapshot of
the file system at a certain point of time. A collection of files and their complete history are stored in a
repository.
28) Mention some of the best graphical GIT client for LINUX?
Some of the best GIT client for LINUX is
a) Git Cola
b) Git-g
c) Smart git
d) Giggle
e) Git GUI
f) qGit
29) What is Subgit? Why to use Subgit?
‘Subgit’ is a tool for a smooth, stress-free SVN to Git migration. Subgit is a solution for a company -
wide migration from SVN to Git that is:
a) It is much better than git-svn
b) No requirement to change the infrastructure that is already placed
c) Allows to use all git and all sub-version features
d) Provides genuine stress –free migration experience.
30) What is the function of ‘git diff ’ in git?
‘git diff ’ shows the changes between commits, commit and working tree etc.
31) What is ‘git status’ is used for?
As ‘Git Status’ shows you the difference between the working directory and the index, it is helpful in
understanding a git more comprehensively.
32) What is the difference between the ‘git diff ’and ‘git status’?
‘git diff’ is similar to ‘git status’, but it shows the differences between various commits and also
between the working directory and index.
33) What is the function of ‘git checkout’ in git?
A ‘git checkout’ command is used to update directories or specific files in your working tree with those
from another branch without merging it in the whole branch.
34) What is the function of ‘git rm’?
To remove the file from the staging area and also off your disk ‘git rm’ is used.
35) What is the function of ‘git stash apply’?
When you want to continue working where you have left your work, ‘git stash apply’ command is used
to bring back the saved changes onto the working directory.
36) What is the use of ‘git log’?
To find specific commits in your project history- by author, date, content or history ‘git log’ is used.
37) What is ‘git add’ is used for?
‘git add’ adds file changes in your existing directory to your index.
38) What is the function of ‘git reset’?
The function of ‘Git Reset’ is to reset your index as well as the working directory to the state of your
last commit.
39) What is git Is-tree?
‘git Is-tree’ represents a tree object including the mode and the name of each item and the SHA-1
value of the blob or the tree.
40) How git instaweb is used?
‘Git Instaweb’ automatically directs a web browser and runs webserver with an interface into your
local repository.
41) What does ‘hooks’ consist of in git?
This directory consists of Shell scripts which are activated after running the corresponding Git
commands. For example, git will try to execute the post-commit script after you run a commit.
42) Explain what is commit message?
Commit message is a feature of git which appears when you commit a change. Git provides you a text
editor where you can enter the modifications made in commits.
43) How can you fix a broken commit?
To fix any broken commit, you will use the command “git commit—amend”. By running this
command, you can fix the broken commit message in the editor.
44) Why is it advisable to create an additional commit rather than amending an existing
commit?
There are couple of reason
a) The amend operation will destroy the state that was previously saved in a commit. If it’s just
the commit message being changed then that’s not an issue. But if the contents are being amended
then chances of eliminating something important remains more.
b) Abusing “git commit- amend” can cause a small commit to grow and acquire unrelated
changes.
45) What is ‘bare repository’ in GIT?
To co-ordinate with the distributed development and developers team, especially when you are
working on a project from multiple computers ‘Bare Repository’ is used. A bare repository comprises
of a version history of your code.
46) Name a few Git repository hosting services
Pikacode
Visual Studio Online
GitHub
GitEnterprise
SourceForge.net
Comments
Post a Comment